Advertisement
Guest User

ISrael

a guest
Nov 18th, 2019
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.79 KB | None | 0 0
  1. // Read the README File Carefully, then write your Algebra Tutor Program Here.
  2. import java.util.Scanner;
  3. import java.util.Random;
  4.  
  5.  
  6. class AlgebraTutor {
  7.    static Scanner user_input = new Scanner(System.in);
  8.     public static void main(String[]args) {
  9.     menu();
  10.     System.out.print("Enter Your Selection:");
  11.     int user_answer =  user_input.nextInt();  
  12.        
  13.     while (user_answer !=4) {
  14.     if (user_answer==1) {
  15.     solveForY();
  16.     menu();
  17.     user_answer =  user_input.nextInt();      
  18.    
  19.     }if (user_answer==2) {
  20.     solveForM();
  21.     menu();
  22.     user_answer =  user_input.nextInt();      
  23.        
  24.     } if  (user_answer==3){
  25.     solveForB();
  26.     menu();
  27.     user_answer =  user_input.nextInt();      
  28.          
  29.     }else {
  30.      System.out.println("You entered an invalid selection!");
  31.      menu();
  32.      user_answer =  user_input.nextInt();  
  33.     }  
  34.     }
  35.        
  36.     }    
  37.      
  38.  
  39.     public static void solveForY() {
  40.        
  41.        Random rand = new Random();
  42.        int min=-100;
  43.        int max=100;  
  44.        int rand1 = rand.nextInt((max-min)+1)+min;
  45.        int rand2 = rand.nextInt((max-min)+1)+min;
  46.        int rand3 = rand.nextInt((max-min)+1)+min;
  47.        
  48.        int m=rand1;
  49.        System.out.println("m="+ m);
  50.        int x=rand2;
  51.        System.out.println("x="+ x);
  52.        int b=rand3;
  53.        System.out.println("b="+ b);
  54.        int y=m*x+b;
  55.        System.out.print("What is the value of Y ?:");
  56.        int y_answer =  user_input.nextInt();  
  57.        
  58.        if (y_answer==y) {
  59.           System.out.println("Correct!");
  60.          
  61.        }else {
  62.             System.out.println("Sorry, that's wrong. The correct answer is:" +y);  
  63.        }      
  64.     }
  65.    
  66.    
  67.      public static void solveForM() {
  68.        Random rand = new Random();
  69.        int min=-100;
  70.        int max=100;  
  71.        double rand1 = rand.nextInt((max-min)+1)+min;
  72.        double rand2 = rand.nextInt((max-min)+1)+min;
  73.        double rand3 = rand.nextInt((max-min)+1)+min;
  74.          
  75.        double y=rand1;
  76.        System.out.println("y="+ y);
  77.        double x=rand2;
  78.        System.out.println("x="+ x);
  79.        double b=rand3;
  80.        System.out.println("b="+ b);
  81.        double a=(y/x);
  82.        double c= (b/x);      
  83.        double m=(a-(c));
  84.        double rounded=Math.round(m*100)/100.0;  
  85.        
  86.        System.out.print("What is the value of M ?:");
  87.        double m_answer =  user_input.nextFloat();  
  88.        
  89.        if (rounded==m_answer) {
  90.           System.out.println("Correct!");
  91.        }else {
  92.             System.out.println("Sorry, that's wrong. The correct answer is:" + rounded);  
  93.        }      
  94.     }
  95.    
  96.      public static void solveForB() {
  97.        Random rand = new Random();
  98.       int min=-100;
  99.        int max=100;  
  100.        int rand1 = rand.nextInt((max-min)+1)+min;
  101.        int rand2 = rand.nextInt((max-min)+1)+min;
  102.        int rand3 = rand.nextInt((max-min)+1)+min;
  103.      
  104.        
  105.        int y=rand1;
  106.        System.out.println("y="+ y);
  107.        int m=rand2;
  108.        System.out.println("m="+ m);
  109.        int x=rand3;
  110.        System.out.println("x="+ x);
  111.        double b=y-(m*x);
  112.        System.out.print("What is the value of b ?:");
  113.        int b_answer =  user_input.nextInt();  
  114.        
  115.        if (b_answer==b) {
  116.           System.out.println("Correct!");
  117.        }else {
  118.             System.out.println("Sorry, that's wrong. The correct answer is:" +b);  
  119.        }      
  120.     }
  121.    
  122.     public static void menu() {
  123.         System.out.println("1) Solve for Y");
  124.         System.out.println("2) Solve for M");
  125.         System.out.println("3) Solve for B");
  126.         System.out.println("4) Quit Program");
  127.         System.out.print("Enter Your Selection:");
  128.        
  129.     }
  130.    
  131.    
  132.                            
  133.    
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement