• API
• FAQ
• Tools
• Archive
daily pastebin goal
30%
SHARE
TWEET

# AlgebraTutot_TimB_11-13

a guest Nov 13th, 2018 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. package Algebra_Tutor;
2.
3. import java.util.Scanner;
4. import java.util.Random;
5.
6. public class main {
7.
8.     public static int generate_random_num(){
9.        Random random_num = new Random();
10.        int rand_num = -100 + random_num.nextInt(200);
11.        return rand_num;
12.     }
13.
15.     System.out.println("Please select from the 3 following modes of study. These will help you break down and understand the line
16.    equation (y = m(x) + b).");
17.     System.out.println("1. Solve for y.");
18.     System.out.println("2. Solve for m.");
19.     System.out.println("3. Solve for b.");
20.     System.out.println("4. Select to quit.");
21.     }
22.
23.     public static boolean solve_for_y(){
24.     int m = generate_random_num();
25.     int x = generate_random_num();
26.     int b = generate_random_num();
27.     int y = 0;
28.     boolean correct = true;
29.     boolean incorrect = false;
30.     Scanner user_input = new Scanner(System.in);
31.
32.     System.out.println("Solve for y in the below equation.");
33.     System.out.println("y = " + m + "(" + x + ") + " + b);
34.     y = user_input.nextInt();
35.     int correct_answer = m * x + b;
36.
38.         System.out.println("Great job! You have entered the correct answer.");
39.         return correct;
40.         }
41.     else if (correct_answer != y){
42.         System.out.println("You have entered an incorrect answer.");
43.         return incorrect;
44.         }
45.     }
46.
47.     public static boolean solve_for_m(){
48.     double m = 0;
49.     int x = generate_random_num();
50.     int b = generate_random_num();
51.     int y = generate_random_num();
52.     boolean correct = true;
53.     boolean incorrect = false;
54.     Scanner user_input = new Scanner(System.in);
55.
56.     System.out.println("Solve for m in the below equation.");
57.     System.out.println(y + " = m(" + x + ") + " + b);
58.     m = user_input.nextDouble();
59.     double correct_answer = (y - b)/(x * 1.0);
60.
62.         System.out.println("Great job!  You have entered the correct answer.");
63.         return correct;
64.         }
65.     else if (correct_answer != y){
66.         System.out.println("You have entered an incorrect answer.");
67.         return incorrect;
68.         }
69.     }
70.
71.     public static boolean solve_for_b(){
72.     int m = generate_random_num();
73.     int x = generate_random_num();
74.     double b = 0;
75.     int y = generate_random_num();
76.     boolean correct = true;
77.     boolean incorrect = false;
78.     Scanner user_input = new Scanner(System.in);
79.
80.     System.out.println("Solve for b in the below equation.");
81.     System.out.println(y + " = " + m + "(" + x + ") + b");
82.     b = user_input.nextDouble();
83.     double correct_answer = y - m * (x * 1.0);
84.
85.
87.         System.out.println("Great job! You have entered the correct answer.");
88.         return correct;
89.         }
90.     else if (correct_answer != b){
91.         System.out.println("You ahve entered an incorrect answer.");
92.         return incorrect;
93.         }
94.     }
95.
96.     public static void Main(String[] args){
97.
98.     Scanner user_input = new Scanner(System.in);
99.     int study_mode = 0;
100.     int correct_count = 0;
101.     int incorrect_count = 0;
102.     int total_questions = 0;
103.
104.     while(study_mode != 4){
106.         study_mode = user_input.nextInt();
107.         if (incorrect_count > 3){
108.             System.out.println("Remember to follow the order of operations.");
109.             incorrect_count = 0;
110.         }
111.         else if (study_mode == 1){
112.              solve_for_y();
113.              if (solve_for_y() == true){
114.              correct_count++;
115.              total_questions++;
116.              }
117.              else {
118.              incorrect_count++;
119.              total_questions++;
120.              }
121.         }
122.         else if (study_mode == 2){
123.              solve_for_m();
124.              if (solve_for_m() == true){
125.              correct_count++;
126.              total_questions++;
127.              }
128.              else {
129.              incorrect_count++;
130.              total_questions++;
131.             }
132.         }
133.         else if (study_mode == 3){
134.              solve_for_b();
135.              if (solve_for_b() == true){
136.              correct_count++;
137.              total_questions++;
138.              }
139.              else {
140.              incorrect_count++;
141.              total_questions++;
142.             }
143.         }
144.
145.     System.out.println("You have quit.");
146.
147.     }
148.   }
149. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top