The program asks the user to enter two integers. Then it asksthree questions: wh
ID: 3614331 • Letter: T
Question
The program asks the user to enter two integers. Then it asksthree questions: what's the product of the two integers, what's thequotient of the two integers, and what's the remainder of thedivision of the two integers. It inputs the answers to each of thequestion from the user, tells the user whether the answer wascorrect or worng, and finally prints a message that depends on howmany correct answers the user provided.
For example, here is a sample run of the program you will write(user inputs are in bold):
Make sure that your program produces output exactly like thesample provided above and that it includes th epercentage ofcorrect answers.
Here are the different messages that should be printed dependingon the number of correct answers:
import java.util.Scanner;
public class Lab3part1
{
publicstatic void main(String[] args){
{
System.out.println("Welcome to my first Booleanprogram!");
System.out.println("This program will ask you to enter 2integers and do " +
"some simple math with them!");
int a;
Scanner keyboard = newScanner(System.in);
System.out.println("Please enter your first number,represented by 'a'; ");
a =keyboard.nextInt();
int b;
Scanner keyboard1 = newScanner(System.in);
System.out.println("Please enter your first number,represented by 'b'; ");
b =keyboard1.nextInt();
boolean a = a/b
Correct Answers Message 0 You did very bad. 1 You did poorly. 2 You did OK. 3 Good job!Explanation / Answer
import java.util.Scanner; import java.io.*; public class Lab3part1 { public static void main(String[]args) { System.out.println("Welcome to my first Boolean program!"); System.out.println("This program will ask you to enter 2 integersand do " + "some simple math with them!"); int a; Scanner keyboard = new Scanner(System.in); System.out.println("Please enter your first number, represented by'a'; "); a =keyboard.nextInt(); int b; Scanner keyboard1 = new Scanner(System.in); System.out.println("Please enter your first number, represented by'b'; "); b =keyboard1.nextInt(); int numCorrect =0; System.out.println("Answer the following Questions"); System.out.println("1. " + a +"*" + b + " =?"); int product =keyboard.nextInt(); if(product ==(a*b)) { System.out.println("Correct"); numCorrect++; } else System.out.println("Wrong!"); System.out.println("2. " + a +"/" + b + "= ?"); int quo =keyboard.nextInt(); if(quo== (a/b)) { System.out.println("Correct"); numCorrect++; } else System.out.println("Wrong!"); System.out.println("3. " + a +"%" + b + "= ?"); int rem =keyboard.nextInt(); if(rem == (a%b)) { System.out.println("Correct"); numCorrect++; } else System.out.println("Wrong!"); if(numCorrect ==0) System.out.println("You did verybad."); else if(numCorrect ==1) System.out.println("You didpoorly."); else if(numCorrect ==2) System.out.println(" You did OK."); else if(numCorrect ==3) System.out.println(" Good job!"); System.out.println("you got " +numCorrect +" correct."); double correct =( ((double)numCorrect)/3) * 100; System.out.println("That's " +correct +"%"); } }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.