Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Read the README File Carefully, then write your Algebra Tutor Program Here.
- import java.util.Scanner;
- import java.util.Random;
- class AlgebraTutor {
- static Scanner user_input = new Scanner(System.in);
- public static void main(String[]args) {
- menu();
- System.out.print("Enter Your Selection:");
- int user_answer = user_input.nextInt();
- while (user_answer !=4) {
- if (user_answer==1) {
- solveForY();
- menu();
- user_answer = user_input.nextInt();
- }if (user_answer==2) {
- solveForM();
- menu();
- user_answer = user_input.nextInt();
- } if (user_answer==3){
- solveForB();
- menu();
- user_answer = user_input.nextInt();
- }else {
- System.out.println("You entered an invalid selection!");
- menu();
- user_answer = user_input.nextInt();
- }
- }
- }
- public static void solveForY() {
- Random rand = new Random();
- int min=-100;
- int max=100;
- int rand1 = rand.nextInt((max-min)+1)+min;
- int rand2 = rand.nextInt((max-min)+1)+min;
- int rand3 = rand.nextInt((max-min)+1)+min;
- int m=rand1;
- System.out.println("m="+ m);
- int x=rand2;
- System.out.println("x="+ x);
- int b=rand3;
- System.out.println("b="+ b);
- int y=m*x+b;
- System.out.print("What is the value of Y ?:");
- int y_answer = user_input.nextInt();
- if (y_answer==y) {
- System.out.println("Correct!");
- }else {
- System.out.println("Sorry, that's wrong. The correct answer is:" +y);
- }
- }
- public static void solveForM() {
- Random rand = new Random();
- int min=-100;
- int max=100;
- double rand1 = rand.nextInt((max-min)+1)+min;
- double rand2 = rand.nextInt((max-min)+1)+min;
- double rand3 = rand.nextInt((max-min)+1)+min;
- double y=rand1;
- System.out.println("y="+ y);
- double x=rand2;
- System.out.println("x="+ x);
- double b=rand3;
- System.out.println("b="+ b);
- double a=(y/x);
- double c= (b/x);
- double m=(a-(c));
- double rounded=Math.round(m*100)/100.0;
- System.out.print("What is the value of M ?:");
- double m_answer = user_input.nextFloat();
- if (rounded==m_answer) {
- System.out.println("Correct!");
- }else {
- System.out.println("Sorry, that's wrong. The correct answer is:" + rounded);
- }
- }
- public static void solveForB() {
- Random rand = new Random();
- int min=-100;
- int max=100;
- int rand1 = rand.nextInt((max-min)+1)+min;
- int rand2 = rand.nextInt((max-min)+1)+min;
- int rand3 = rand.nextInt((max-min)+1)+min;
- int y=rand1;
- System.out.println("y="+ y);
- int m=rand2;
- System.out.println("m="+ m);
- int x=rand3;
- System.out.println("x="+ x);
- double b=y-(m*x);
- System.out.print("What is the value of b ?:");
- int b_answer = user_input.nextInt();
- if (b_answer==b) {
- System.out.println("Correct!");
- }else {
- System.out.println("Sorry, that's wrong. The correct answer is:" +b);
- }
- }
- public static void menu() {
- System.out.println("1) Solve for Y");
- System.out.println("2) Solve for M");
- System.out.println("3) Solve for B");
- System.out.println("4) Quit Program");
- System.out.print("Enter Your Selection:");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement