tutor - result = left - right; reps = 2; break; case 3: //...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
public class tutor { public static void main(String[] args) { Scanner kb = new Scanner(System.in); int choice; int left, right; // operands int result; // correct result result = 0; int answer; // user answer answer = 0; int reps; reps = 0; Random rand = new Random(); // Initialize generator, default start is time of day // repeat until the user quits do { // show menu System.out.println("0) quit"); System.out.println("1) addition"); System.out.println("2) subtraction"); System.out.println("3) multiplication"); System.out.println("4) integer division"); System.out.println("5) help"); // get problem type System.out.println("Enter choice"); choice = kb.nextInt(); // generate random problem left = rand.nextInt(13); // [0,12] right = rand.nextInt(13); // [0,12] switch (choice) { case 1: // addition System.out.println("What is " + left + "+" + right + " ?"); result = left + right; reps = 1; break; case 2: // subtraction System.out.println("What is " + left + "-" + right + " ?");
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: result = left - right; reps = 2; break; case 3: // multiplication System.out.println("What is " + left + "*" + right + " ?"); result = left * right; reps = 3; break; case 4: // integer division System.out.println("What is " + left + "/" + right + " ?"); result = left / right; reps = 4; break; case 5: // help for (int row=1; row <= 12; row++) { for (int col=1; col <=12; col++) System.out.printf("%5d", row * col); System.out.println(); } break; case 0: // do nothing (quit) break; default: System.out.println("Invalid choice, try again"); } // get answer answer = kb.nextInt(); // repeat number of reps times while (answer != result && reps > 1) { System.out.println("Sorry - wrong. Try again: "); reps--; answer = kb.nextInt(); } // cbeck if right or not if (answer == result) System.out.println("Correct!"); else System.out.println("Wrong."); } while (choice != 0); } }...
View Full Document

Page1 / 2

tutor - result = left - right; reps = 2; break; case 3: //...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online