Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.Random;
- public class AlgebraTutor {
- static Random random = new Random();
- static int m = -100 + random.nextInt(201);
- static int x = -100 + random.nextInt(201);
- static int b = -100 + random.nextInt(201);
- static int y = -100 + random.nextInt(201);
- static int correct_answer_y = (m * x) + b;
- static int correct_answer_m = (y - b) / x;
- static int correct_answer_b = (y - (m * x));
- static Scanner input = new Scanner(System.in);
- static Scanner selection = new Scanner(System.in);
- static int user_selection = 0;
- public static void main(String[] args) {
- while (user_selection != 4) {
- prompt();
- }
- }
- public static void prompt() {
- System.out.println("If you would like to solve for y, please enter 1.");
- System.out.println("If you would like to solve for m, please enter 2.");
- System.out.println("If you would like to solve for b, please enter 3.");
- System.out.println("If you would like to quit, please enter 4.");
- int user_selection = input.nextInt();
- while ((user_selection != 1) && (user_selection != 2) && (user_selection != 3) && (user_selection != 4)) {
- user_selection = input.nextInt();
- }
- if (user_selection == 1) {
- solveForY();
- }
- if (user_selection == 2) {
- solveForM();
- }
- if (user_selection == 3) {
- solveForB();
- }
- if (user_selection == 4) {
- System.exit(0);
- }
- }
- public static boolean solveForY() {
- System.out.println("Given: \n");
- System.out.println("m = " + m);
- System.out.println("x = " + x);
- System.out.println("b = " + b);
- System.out.println();
- System.out.print("What is the value of y? ");
- int user_answer = input.nextInt();
- if (user_answer != correct_answer_y) {
- System.out.println("Sorry, that's wrong. The answer is " + correct_answer_y);
- }
- else {
- System.out.println("Correct!");
- }
- return (user_answer != correct_answer_y);
- }
- public static boolean solveForM() {
- System.out.println("Given: \n");
- System.out.println("y = " + y);
- System.out.println("x = " + x);
- System.out.println("b = " + b);
- System.out.println();
- System.out.print("What is the value of m? ");
- int user_answer = input.nextInt();
- if (user_answer != correct_answer_m) {
- System.out.println("Sorry, that's wrong. The answer is " + correct_answer_m + ".");
- }
- else {
- System.out.println("Correct!");
- }
- return (user_answer != correct_answer_m);
- }
- public static boolean solveForB() {
- System.out.println("Given: \n");
- System.out.println("y = " + y);
- System.out.println("x = " + x);
- System.out.println("m = " + m);
- System.out.println();
- System.out.print("What is the value of b? ");
- int user_answer = input.nextInt();
- if (user_answer != correct_answer_b) {
- System.out.println("Sorry, that's wrong. The answer is " + correct_answer_b + ".");
- }
- else {
- System.out.println("Correct!");
- }
- return (user_answer != correct_answer_b);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement