In: Computer Science
I am struggling with this assignment for my java class.
Objectives: Your program will be graded according to the rubric below. Please review each objective before submitting your work so you don’t lose points.
1.Create a new project and class in Eclipse and add the main method. (5 points)
2. Construct a Scanner to read input from the keyboard. (5 points)
3. Prompt the user with three questions from the Psychology Today quiz, and use the Scanner to read their responses. (15 points)
4. Use conditional statements, logical operators, and String methods to check if each user response is either “yes” or “y” with arbitrary capitalization. (30 points).
5. Use an accumulator to track the number of statements that the user agrees with. (15 points)
6. Use a cascading if-else statement to print the result of the quiz that corresponds to the value stored in the accumulator. (20 points)
7. Use meaningful variable names, consistent indentation, and whitespace (blank lines and spaces) to make your code readable. Add comments where appropriate to explain the overall steps of your program. (10 points)
Sample Output: Below is an example run of the program.
The user input is in bold. Psychology Today Quiz: Are You Stressed Out? -------------------------------------------- Do you agree with the following statements?
1. I am losing my sense of humor. Yes
2. I find it more and more difficult to see people socially. no
3. I feel tired most of the time. y You are possibly stressed out.
Choose any three of the twelve statements from the Psychology Today quiz to include in your program. The final line of output should depend on the number of yes responses. The possible final lines are shown in the following table: Yes responses Final output line 0 You may be more exhausted than stressed out. 1 You may be beginning to stress out. 2 You are possibly stressed out. 3 You are probably stressed out. Note that you can print a blank line by calling System.out.println with no argument.
//----------- Quiz.java ---------
//import Scanner class to take input from user.
import java.util.Scanner;
public class Quiz
{
public static void main(String[] args)
{
//create scanner object
Scanner in = new
Scanner(System.in);
//accumulator for keep tracking of
count of yes
int countYes = 0;
// to store user answer
String answer;
//print heading
System.out.println("Psychology
Today Quiz: Are You Stressed Out? ");
System.out.println("--------------------------------------------
");
System.out.println("Do you agree
with the following statements?");
System.out.println();
//prompt question and take answer
from user.
System.out.print("1. I am losing my
sense of humor. ");
answer =
in.nextLine().trim();
//use equalsIgnoreCase() method to
compare the answer enetered
//in case insensitive mode.
//if user enetered yes or y in any
case increment count.
if(answer.equalsIgnoreCase("yes")
|| answer.equalsIgnoreCase("y"))
{
countYes++;
}
System.out.println();
System.out.print("2. I find it more
and more difficult to see people socially. ");
answer =
in.nextLine().trim();
if(answer.equalsIgnoreCase("yes")
|| answer.equalsIgnoreCase("y"))
{
countYes++;
}
System.out.println();
System.out.print("3. I feel tired
most of the time. ");
answer =
in.nextLine().trim();
System.out.println();
if(answer.equalsIgnoreCase("yes")
|| answer.equalsIgnoreCase("y"))
{
countYes++;
}
//if number of yes are 0 then print
exhausted
if(countYes == 0)
{
System.out.println("You may be more exhausted than stressed
out.");
}
//if no.of yes are 1 then print
beginning to stressed out.
else if(countYes == 1)
{
System.out.println("You may be beginning to stress out.");
}
//if not then print possibly
stressed out.
else
{
System.out.println("You are possibly stressed out.");
}
}
}
//PLEASE LIKE THE ANSWER.