Hi, I need a quick program written, going to check with mine, as mine has quite
ID: 3528160 • Letter: H
Question
Hi, I need a quick program written, going to check with mine, as mine has quite a lot of syntax errors. This is a sample transcript of what your program should do. Items should present the user with a math problem generated randomly (but with the same base function described below) and have user input solve them. Enter your name: Jeremy Welcome Jeremy! Please answer the following questions: 4 + 6 = 10 Correct! 4 * 6 = 24 Correct! 4 / 6 = 1 Wrong! The correct answer is 0 4 % 6 = 4 Correct! You got 3 correct answers That's 75.0%! Another example: Enter your name: Bob Welcome Bob! Please answer the following questions: 3 + 3 = 0 Wrong! The correct answer is 6 3 * 3 = 6 Wrong! The correct answer is 9 3 / 3 = 0 Wrong! The correct answer is 1 3 % 3 = 1 Wrong! The correct answer is 0 You got 0 correct answers That's 0.0%!Explanation / Answer
import java.util.*; import java.io.*; class J { public static void main(String arg[]) throws IOException { String name; int count=0; System.out.print("Enter you name:"); Random rand=new Random(); InputStreamReader converter = new InputStreamReader(System.in); BufferedReader in = new BufferedReader(converter); name=in.readLine(); System.out.print("Welcome"+name+"please solve the following"); int r1=rand.nextInt()%20; int r2=rand.nextInt()%20; System.out.print(r1+"+"+r2+"="); Scanner s=new Scanner(System.in); int res=s.nextInt(); if(res==r1+r2) { System.out.print("Correct "); count++; } else{ System.out.print("Wrong "); System.out.print("the correctt answer is"+r1+r2); } System.out.print(r1+"*"+r2+"="); Scanner s1=new Scanner(System.in); int res1=s1.nextInt(); if(res1==r1*r2) { System.out.print(" Correct"); count++; } else{ System.out.print("Wrong"); System.out.print("the correctt answer is"+(r1*r2)); } System.out.print(r1+"/"+r2+"="); Scanner s2=new Scanner(System.in); int res2=s.nextInt(); if(res2==r1/r2) { System.out.print("Correct"); count++; } else{ System.out.print("Wrong"); System.out.print("the correctt answer is"+(r1/r2)); } System.out.print(r1+"%"+r2+"="); Scanner s3=new Scanner(System.in); int res3=s.nextInt(); if(res3==r1%r2) { System.out.print("Correct"); count++; } else{ System.out.print("Wrong"); System.out.print("the correctt answer is"+(r1%r2)); } System.out.print("You got"+count+"answers.Thats"+count*25+"%"); } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.