Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Algebra_Tutor;
- import java.util.Scanner;
- import java.util.Random;
- public class main {
- public static int generate_random_num(){
- Random random_num = new Random();
- int rand_num = -100 + random_num.nextInt(200);
- return rand_num;
- }
- public static void display_menu(){
- System.out.println("Please select from the 3 following modes of study. These will help you break down and understand the line
- equation (y = m(x) + b).");
- 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. Select to quit.");
- }
- public static boolean solve_for_y(){
- int m = generate_random_num();
- int x = generate_random_num();
- int b = generate_random_num();
- int y = 0;
- boolean correct = true;
- boolean incorrect = false;
- Scanner user_input = new Scanner(System.in);
- System.out.println("Solve for y in the below equation.");
- System.out.println("y = " + m + "(" + x + ") + " + b);
- y = user_input.nextInt();
- int correct_answer = m * x + b;
- if (correct_answer == y){
- System.out.println("Great job! You have entered the correct answer.");
- return correct;
- }
- else if (correct_answer != y){
- System.out.println("You have entered an incorrect answer.");
- return incorrect;
- }
- }
- public static boolean solve_for_m(){
- double m = 0;
- int x = generate_random_num();
- int b = generate_random_num();
- int y = generate_random_num();
- boolean correct = true;
- boolean incorrect = false;
- Scanner user_input = new Scanner(System.in);
- System.out.println("Solve for m in the below equation.");
- System.out.println(y + " = m(" + x + ") + " + b);
- m = user_input.nextDouble();
- double correct_answer = (y - b)/(x * 1.0);
- if (correct_answer == m){
- System.out.println("Great job! You have entered the correct answer.");
- return correct;
- }
- else if (correct_answer != y){
- System.out.println("You have entered an incorrect answer.");
- return incorrect;
- }
- }
- public static boolean solve_for_b(){
- int m = generate_random_num();
- int x = generate_random_num();
- double b = 0;
- int y = generate_random_num();
- boolean correct = true;
- boolean incorrect = false;
- Scanner user_input = new Scanner(System.in);
- System.out.println("Solve for b in the below equation.");
- System.out.println(y + " = " + m + "(" + x + ") + b");
- b = user_input.nextDouble();
- double correct_answer = y - m * (x * 1.0);
- if (correct_answer == b){
- System.out.println("Great job! You have entered the correct answer.");
- return correct;
- }
- else if (correct_answer != b){
- System.out.println("You ahve entered an incorrect answer.");
- return incorrect;
- }
- }
- public static void Main(String[] args){
- Scanner user_input = new Scanner(System.in);
- int study_mode = 0;
- int correct_count = 0;
- int incorrect_count = 0;
- int total_questions = 0;
- while(study_mode != 4){
- display_menu();
- study_mode = user_input.nextInt();
- if (incorrect_count > 3){
- System.out.println("Remember to follow the order of operations.");
- incorrect_count = 0;
- }
- else if (study_mode == 1){
- solve_for_y();
- if (solve_for_y() == true){
- correct_count++;
- total_questions++;
- }
- else {
- incorrect_count++;
- total_questions++;
- }
- }
- else if (study_mode == 2){
- solve_for_m();
- if (solve_for_m() == true){
- correct_count++;
- total_questions++;
- }
- else {
- incorrect_count++;
- total_questions++;
- }
- }
- else if (study_mode == 3){
- solve_for_b();
- if (solve_for_b() == true){
- correct_count++;
- total_questions++;
- }
- else {
- incorrect_count++;
- total_questions++;
- }
- }
- System.out.println("You have quit.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement