Question

Solve for y, m and b. Add 2 choices that behave similarly to your part 1...

Solve for y, m and b. Add 2 choices that behave similarly to your part 1 program, but have the user solve for m and b instead. These choices should also randomly generate problems, and print if the user answers correctly. Your main program should display a menu asking which type of question to ask: Select 1 to Solve for Y, 2 to Solve for M, 3 to Solve for B and 4 to quit. When the user selects the question type, one question should be asked, then the user should return to the menu. This should repeat until the user selects quit, then the program should exit. Use one or more methods and loops to produce this behavior.

Here is what i have so far (i've bolded where i need help), and i cannot figure out what to do from here. I have a general idea, but no clue how to execute.

// Read the README File Carefully, then write your Algebra Tutor Program Here.
import java.util.Scanner; //reads user input
import java.util.Random; //generates random numbers
public class AlgebraTutor {
public static boolean solveForTheValueOfY(int m, int x, int b, int user_answer) {
int y = (m * x) + b;
if (y == user_answer) {
System.out.println("Correct!");
return true;
} else {
System.out.println("Sorry, that is incorrect. The correct answer is " + y + ".");
return false;
}
}
  
public static boolean solveForTheValueOfM(int y, int x, int b, int user_answer) {
int m = (y - b) / x;
if (m == user_answer) {
System.out.println("Correct!");
return true;
} else {
System.out.println("Sorry, that is incorrect. The correct answer is " + m + ".");
return false;
}
}
  
public static boolen solveForTheValueOfB(int m, int x, int y, int user_answer) {
int b = -(m * x) + y;
if (b == user_answer) {
System.out.println("Correct!");
return true;
} else {
System.out.println("Sorry, that is incorrect. The correct answer is " + b + ".");
return false;
}
}
  
public static void practiceQuestions(char variableOne, char variableTwo, char VariableThree, int user_option) {
Scanner user_input = new Scanner(System.in);
Random random = new Random();
  
int firstNumber = random.nextInt(100) +- 100;
int secondNumber = random.nextInt(100) +- 100;
int thirdNumber = random.nextInt(100) +- 100;
  
System.out.println("Given: " + variableOne + " = " + firstNumber);
System.out.println(" " + variableTwo + " = " + secondNumber);
System.out.println(" " + variableThree + " = " + thirdNumber);
  
if (user_option == 1) {
System.out.println("What is the value of y? ");
solveForTheValueOfY(firstNumber, secondNumber, thirdNumber, user_option);
} else if (user_option == 2) {
System.out.println("What is the value of m? ");
solveForTheValueOfM(firstNumber, secondNumber, thirdNumber, user_option);
} else if {
System.out.println("What is the value of b? ");
solveForTheValueOfN(firstNumber, secondNumber, thirdNumber, user_option);
}
}
  
//ask the student which practice questions they would like to solve.
public static void main(String [] args) {
Scanner user_input = new Scanner(System.in);
int user_option = 0;
  
System.out.
println("Which type of question would you like to be asked?");
while {//present the 3 modes and exit
System.out.println("Select 1 to Solve for Y");
System.out.println("2 to Solve for M");
System.out.println("3 to Solve for B");
System.out.println("4 to quit");
  
user_option = user_input.nextInt();
}
}
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Random; //generates random numbers
import java.util.Scanner; //reads user input

public class AlgebraTutor {
   public static boolean solveForTheValueOfY(int m, int x, int b, int user_answer) {
       int y = (m * x) + b;
       if (y == user_answer) {
           System.out.println("Correct!");
           return true;
       } else {
           System.out.println("Sorry, that is incorrect. The correct answer is " + y + ".");
           return false;
       }
   }

   public static boolean solveForTheValueOfM(int y, int x, int b, int user_answer) {
       int m = (y - b) / x;
       if (m == user_answer) {
           System.out.println("Correct!");
           return true;
       } else {
           System.out.println("Sorry, that is incorrect. The correct answer is " + m + ".");
           return false;
       }
   }

   public static boolean solveForTheValueOfB(int m, int x, int y, int user_answer) {
       int b = -(m * x) + y;
       if (b == user_answer) {
           System.out.println("Correct!");
           return true;
       } else {
           System.out.println("Sorry, that is incorrect. The correct answer is " + b + ".");
           return false;
       }
   }

   public static void practiceQuestions(char variableOne, char variableTwo, char variableThree, int user_option) {
       Scanner user_input = new Scanner(System.in);
       Random random = new Random();

       int firstNumber = random.nextInt(100) + -100;
       int secondNumber = random.nextInt(100) + -100;
       int thirdNumber = random.nextInt(100) + -100;

       System.out.println("Given: " + variableOne + " = " + firstNumber);
       System.out.println(" " + variableTwo + " = " + secondNumber);
       System.out.println(" " + variableThree + " = " + thirdNumber);

       if (user_option == 1) {
           System.out.println("What is the value of y? ");
           int user_answer = user_input.nextInt();
           solveForTheValueOfY(firstNumber, secondNumber, thirdNumber, user_answer);
       } else if (user_option == 2) {
           System.out.println("What is the value of m? ");
           int user_answer = user_input.nextInt();
           solveForTheValueOfM(firstNumber, secondNumber, thirdNumber, user_answer);
       } else {
           System.out.println("What is the value of b? ");
           int user_answer = user_input.nextInt();
           solveForTheValueOfB(firstNumber, secondNumber, thirdNumber, user_answer);
       }
   }

   // ask the student which practice questions they would like to solve.
   public static void main(String[] args) {
       Scanner user_input = new Scanner(System.in);
       int user_option = 0;

       while (user_option != 4) {// present the 3 modes and exit
           System.out.println("Which type of question would you like to be asked?");
           System.out.println("Select 1 to Solve for Y");
           System.out.println("2 to Solve for M");
           System.out.println("3 to Solve for B");
           System.out.println("4 to quit");

           user_option = user_input.nextInt();

           if (user_option == 4)
               break;

           // Call for the practiceQuestions method
           practiceQuestions('m', 'x', 'b', user_option);

       }
   }
}

Screenshot of Output:

Add a comment
Know the answer?
Add Answer to:
Solve for y, m and b. Add 2 choices that behave similarly to your part 1...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT