Question
hello i want to add these methods to my code that i write it down please implement these methods with my code please solve it
hello i want to add these methods to my code that i write it down please implement these methods with my code please solve it in clean way thank you in advance.
you can enhance my code above if it necessary .
1-create a method called (start) that ask the user to inter start word to start running the Arithmetic Exercise program
2- create a method called (rORq) that ask user if want to restart the An Arithmetic Exercise Program or want to quit
javajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajav
3-create a method called (timer) that stop the Arithmetic Exercise Program from running after 1 minutes
------------------------------------------------------------------------------------------------------------------------------------------------------
package try2;
import java.util.Scanner;
/** * * @author Zainab */ public class Try2 {
public static void main(String[] args) { Scanner input = new Scanner(System.in);
long starttime = System.currentTimeMillis(); int x = (int) (Math.random() * 10) + 10; int y = (int) (Math.random() * 10) + 10; int b = (int) (Math.random() * 10) + 10; int correctCount = 0; // Count the number of correct answers int count = 0; // Count the number of questions String output = ""; // output string is initially empty while (count < 5) { if (level1(x, y)) { correctCount++; } count++; } long endTime = System.currentTimeMillis(); long testTime = getTestTime(starttime, endTime); System.out.println("Correct count is " + correctCount+ " Test time is " + testTime + " seconds out of 90 seconds "); System.out.println("total num of q is: "+count); if (correctCount == count && testTime <= 90) { System.out.println("you can move to next level"); correctcount2(x, y, b); } else { System.out.println("you failed"); } }
public static long getTestTime(long starttime, long endTime) { return (endTime - starttime) / 1000; }
public static boolean level1(int x, int y) { Scanner input = new Scanner(System.in);
x = (int) (Math.random() * 10) + 10; y = (int) (Math.random() * 10) + 10;
int z = 0; int min = 0; int max = 4; // exclusive int num = (int) (Math.random() * (max - min) + min); char operator = ' ';
switch (num) { case 0: z = x + y; operator = '+'; break; case 1: operator = '-'; z = x - y; break; case 2: operator = '*'; z = x * y; break; case 3: operator = '/'; z = x / y; break; default: operator = '?'; }
System.out.println(x + " " + operator + " " + y); System.out.println("....."); int val = input.nextInt(); if (z == val) { System.out.println("Correct"); return true; } else { System.out.println("Wrong"); return false; }
}
public static boolean level2(int x, int y, int b) { Scanner input = new Scanner(System.in);
x = (int) (Math.random() * 10) + 10; y = (int) (Math.random() * 10) + 10; b = (int) (Math.random() * 10) + 10; int z = 0; int min = 0; int max = 4; // exclusive int num = (int) (Math.random() * (max - min) + min); char operator = ' ';
switch (num) { case 0: z = x + y + b; operator = '+'; break; case 1: operator = '-'; z = x - y - b; break; case 2: operator = '*'; z = x * y * b; break; case 3: operator = '/'; z = x / y / b; break; default: operator = '?'; } System.out.println(x + " " + operator + " " + y + operator + b); System.out.println("....."); int val = input.nextInt(); if (z == val) { System.out.println("Correct"); return true; } else { System.out.println("Wrong"); return false; } }
public static void correctcount2(int x, int y, int b) { Scanner input = new Scanner(System.in);
int correctCount = 0; // Count the number of correct answers int count = 0; // Count the number of questions String output = ""; // output string is initially empty while (count < 5) { if (level2(x, y, b)) { correctCount++; } count++; } System.out.println("Correct count is " + correctCount++); }
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started