The problem is: The program asks the user to enter two integers. Then it asks th
ID: 3620848 • Letter: T
Question
The problem is:The program asks the user to enter two integers. Then it asks three questions: what's the product of the two integers, what's the quotient of the two integers, and what's the remainder of the division of the two integers. It inputs the answers to each of the question from the user, tells the user whether the answer was correct or worng, and finally prints a message that depends on how many correct answers the user provided.
For example, here is a sample run of the program you will write (user inputs are in bold):
----------------------
MATH QUESTIONS
----------------------
Please enter an integer.
5
Please enter another integer.
3
Answer the following questions:
1. 5 * 3 = ?
17
Wrong!
2. 5 / 3 = ?
1
Correct.
3. 5 % 3 = ?
2
Correct.
You did OK.
You got 2 correct.
That's 66.66667%
Make sure that your program produces output exactly like the sample provided above and that it includes th epercentage of correct answers.
Here are the different messages that should be printed depending on the number of correct answers:
Correct Answers Message
0 You did very bad.
1 You did poorly.
2 You did OK.
3 Good job!
My work is:
public static void main(String[] args){
Scanner keyboard = new Scanner(System.in);
int Int1, Int2, Product, Quotient, Remainder, UserAnswer1, UserAnswer2, UserAnswer3;
System.out.println("");
System.out.println("----------------------");
System.out.println(" MATH QUESTIONS ");
System.out.println("----------------------");
System.out.println("");
System.out.println("Please enter an integer.");
Int1 = keyboard.nextInt();
System.out.println("Please enter another integer.");
Int2 = keyboard.nextInt();
System.out.println("");
System.out.println("Answer the following questions:");
System.out.println("");
Product = Int1 * Int2;
Quotient = Int1 / Int2;
Remainder = Int1 % Int2;
//Problem 1.
System.out.println("1. " + Int1 + "*" + Int2 + "=");
UserAnswer1 = keyboard.nextInt();
if (Product == UserAnswer1)
{
System.out.println("Correct.");
}
if (Product != UserAnswer1)
{
System.out.println("Wrong!");
}
System.out.println("");
// Problem 2.
System.out.println("2. " + Int1 + "/" + Int2 + "=");
UserAnswer2 = keyboard.nextInt();
if (Quotient == UserAnswer2)
{
System.out.println("Correct.");
}
if (Quotient != UserAnswer2)
{
System.out.println("Wrong!");
}
System.out.println("");
//Problem 3.
System.out.println("3. " + Int1 + "%" + Int2 + "=");
UserAnswer3 = keyboard.nextInt ();
if (Remainder == UserAnswer3)
{
System.out.println("Correct.");
}
if (Remainder != UserAnswer3)
{
System.out.println("Wrong!");
}
System.out.println("");
// Math complete. Now set up the different score messages and percentages.
}
}
I need help finishing this program by calculating the percentages. Thank you.
Explanation / Answer
please rate - thanks import java.util.*;public class main
{
public static void main(String[] args){
Scanner keyboard = new Scanner(System.in);
int Int1, Int2, Product, Quotient, Remainder, UserAnswer1, UserAnswer2, UserAnswer3;
int count=0;
double percent;
System.out.println("");
System.out.println("----------------------");
System.out.println(" MATH QUESTIONS ");
System.out.println("----------------------");
System.out.println("");
System.out.println("Please enter an integer.");
Int1 = keyboard.nextInt();
System.out.println("Please enter another integer.");
Int2 = keyboard.nextInt();
System.out.println("");
System.out.println("Answer the following questions:");
System.out.println("");
Product = Int1 * Int2;
Quotient = Int1 / Int2;
Remainder = Int1 % Int2;
//Problem 1.
System.out.println("1. " + Int1 + "*" + Int2 + "=");
UserAnswer1 = keyboard.nextInt();
if (Product == UserAnswer1)
{count++;
System.out.println("Correct.");
}
if (Product != UserAnswer1)
{
System.out.println("Wrong!");
}
System.out.println("");
// Problem 2.
System.out.println("2. " + Int1 + "/" + Int2 + "=");
UserAnswer2 = keyboard.nextInt();
if (Quotient == UserAnswer2)
{count++;
System.out.println("Correct.");
}
if (Quotient != UserAnswer2)
{
System.out.println("Wrong!");
}
System.out.println("");
//Problem 3.
System.out.println("3. " + Int1 + "%" + Int2 + "=");
UserAnswer3 = keyboard.nextInt ();
if (Remainder == UserAnswer3)
{count++;
System.out.println("Correct.");
}
if (Remainder != UserAnswer3)
{
System.out.println("Wrong!");
}
System.out.println("");
// Math complete. Now set up the different score messages and percentages.
if(count==3)
System.out.println("Good job!");
else if(count==2)
System.out.println("You did OK.");
else if(count==1)
System.out.println("You did poorly.");
else
System.out.println("You did very bad.");
System.out.println("You got "+count+" correct.");
percent=count/3.*100.;
System.out.printf("That's %8.5f%%",percent);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.