/******************************************************************************* The mixture testing program including Addition, Subtraction, Multiplication, Division (integer) and Mudular: This program will generates two random numbers REPEATEDLY and invite the user to input the answer. It will then check the answer and report 'right' or 'wrong'. The user can choose to do any of the five types of calculations and decide to continue or finish. 22 Oct 07 By Ida Pu ********************************************************************************/ import java.util.Scanner; import java.util.Random; import java.text.Collator; public class t7 { public static void main(String args []) { Scanner keyboard = new Scanner(System.in); Random r= new Random(); boolean finish = false; while (!finish) { int n1=1+r.nextInt(10); int n2=1+r.nextInt(10); System.out.println("What would you like to do?\n 1 addition\n 2 subtraction\n 3 multiplication \n 4 division (integer) \n 5 mudular"); int select1 = keyboard.nextInt(); if (select1==1) { System.out.println(n1+" + "+n2+"=? "); } else if (select1==2) { System.out.println(n1+" - "+n2+"=? "); } else if (select1==3) { System.out.println(n1+" x "+n2+"=? "); } else if (select1==4) { System.out.println(n1+" div "+n2+"=? "); } else { System.out.println(n1+" mod "+n2+"=? (integer part)"); } System.out.println("Please input your answer (integer part only)"); int answer = keyboard.nextInt(); if (select1==1) { if ((n1+n2)==answer) { System.out.println("Correct!"); } else { System.out.println("Wrong!"); } } else if (select1==2) { if ((n1-n2)==answer) { System.out.println("Correct!"); } else { System.out.println("Wrong!"); } } else if (select1==3) { if ((n1*n2)==answer) { System.out.println("Correct!"); } else { System.out.println("Wrong!"); } } else if (select1==4) { if ((n1/n2)==answer) { System.out.println("Correct!"); } else { System.out.println("Wrong!"); } } else { if ((n1%n2)==answer) { System.out.println("Correct!"); } else { System.out.println("Wrong!"); } } System.out.println("Would you like to try again? (1 to continue; and 0 to finish)"); int select = keyboard.nextInt(); if (select==1) { finish=false; } else { finish=true; System.out.println("Bye!"); } } } }