Write a program that present the following proverbs one at a time and promote th
ID: 3785800 • Letter: W
Question
Write a program that present the following proverbs one at a time and promote the user to evaluate them as true or false. The program should then tell the user how many questions were answered correctly and display one of the following evaluations: Perfect (all correct), Excellent (5 or 6 correct), Good (3 or 4 correct), Poor (0 to 2 correct).
Proverb
Truth Value
The squeaky wheel gets the grease.
True
Cry and you cry alone.
True
Opposite attract.
False
Spare the rod and spoil the child.
False
Actions speak louder than words.
True
Familiarity breeds contempt.
False
Marry in house, repent at leisure.
True
Proverb
Truth Value
The squeaky wheel gets the grease.
True
Cry and you cry alone.
True
Opposite attract.
False
Spare the rod and spoil the child.
False
Actions speak louder than words.
True
Familiarity breeds contempt.
False
Marry in house, repent at leisure.
True
Explanation / Answer
ProverbTest.java
import java.util.Scanner;
public class ProverbTest {
public static void main(String[] args) {
String proverbs[] = {"The squeaky wheel gets the grease.","Cry and you cry alone.","Opposite attract.","Spare the rod and spoil the child.","Actions speak louder than words.","Familiarity breeds contempt.","Marry in house, repent at leisure."};
boolean correctAnswers[] = {true, true, false, false, true, false, true};
boolean userAnswers[] = new boolean[correctAnswers.length];
Scanner scan = new Scanner(System.in);
for(int i=0; i<proverbs.length; i++){
System.out.println(proverbs[i]);
System.out.println("Enter your answer: ");
userAnswers[i] = scan.nextBoolean();
}
int totalCorrectAnswers = 0;
for(int i=0; i<correctAnswers.length; i++){
if(correctAnswers[i] == userAnswers[i]){
totalCorrectAnswers++;
}
}
if(totalCorrectAnswers == correctAnswers.length){
System.out.println("Perfect");
}
else if(totalCorrectAnswers == 5 || totalCorrectAnswers == 6){
System.out.println("Excellent");
}
else if(totalCorrectAnswers == 3 || totalCorrectAnswers == 4){
System.out.println("Good");
}
else{
System.out.println("Poor");
}
}
}
Output:
The squeaky wheel gets the grease.
Enter your answer:
true
Cry and you cry alone.
Enter your answer:
false
Opposite attract.
Enter your answer:
false
Spare the rod and spoil the child.
Enter your answer:
true
Actions speak louder than words.
Enter your answer:
true
Familiarity breeds contempt.
Enter your answer:
true
Marry in house, repent at leisure.
Enter your answer:
false
Good
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.