Question

In: Computer Science

I am struggling with this assignment for my java class. Objectives: Your program will be graded...

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.

Solutions

Expert Solution

//----------- 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.


Related Solutions

I have the following code for my java class assignment but i am having an issue...
I have the following code for my java class assignment but i am having an issue with this error i keep getting. On the following lines: return new Circle(color, radius); return new Rectangle(color, length, width); I am getting the following error for each line: "non-static variable this cannot be referenced from a static context" Here is the code I have: /* * ShapeDemo - simple inheritance hierarchy and dynamic binding. * * The Shape class must be compiled before the...
Hello i am working on an assignment for my programming course in JAVA. The following is...
Hello i am working on an assignment for my programming course in JAVA. The following is the assignment: In main, first ask the user for their name, and read the name into a String variable. Then, using their name, ask for a temperature in farenheit, and read that value in. Calculate and print the equivalent celsius, with output something like Bob, your 32 degrees farenheit would be 0 degrees celsius Look up the celsius to farenheit conversion if you do...
I am struggling with Mechanism problems in my organic Chemistry 1 class. Can you explain how...
I am struggling with Mechanism problems in my organic Chemistry 1 class. Can you explain how SN1, SN2, E1 and E2 play a role in mechanisms and everything else that is involved with a mechanism problems (like maybe doing a practice problem and explaining it step by step would be a big help). Thank you!!!!!
I need to draw my first name using Turtle. I am struggling with "P" and "A"...
I need to draw my first name using Turtle. I am struggling with "P" and "A" this is what I have import turtle turtle.setup(800, 700) window = turtle.Screen() window.reset() window.bgcolor('cornsilk') t = turtle.Turtle() t.color('blue') t.pencolor('red') t.turtlesize(6) t.speed(2) t.up() t.setposition(-50, 0) t.pendown()#Drawing letter T t.forward(40) t.back(20) t.right(90) t.forward(50) t.left(90) t.penup() t.forward(70) t.left(90) t.forward(25) t.pendown() t.circle(25)# Drawing letter O t.penup() t.left(180) t.forward(25) t.left(90) t.forward(10) t.pendown()#Drawing letter N t.left(90) t.forward(50) t.right(150) t.forward(60) t.left(150) t.forward(53) t.back(53) t.right(90) turtle.done()
I am struggling to even get started on this assignment. its a teach yourself kind of...
I am struggling to even get started on this assignment. its a teach yourself kind of situation and I have and no issues up to this point but I just can't wrap my head around it. Implement the Account class. Add a public enum called ACCOUNT_TYPE with two values CHECKING, SAVING Add the following private instance variables to the Account class: An instance variable called aType of type Enum ACCOUNT_TYPE. An instance variable called accountOwner of type String. An instance...
I am struggling with easy problem. Can you pls check my work ? The patient is...
I am struggling with easy problem. Can you pls check my work ? The patient is to receive 500 mL of D5W over 6 hours . What is the drip rate per minute if the tubing provides 12 gtts per mL? Gtt/min 12gtt/ml x 500/360 min =6000/360=118 gtt/min A patient who weighs 74 pounds has an order for Advil (ibuprofen) 3.5 mg/kg every 6 hours. How many mg will you give in a single dose? 3,5MG /KG X33.6KG =118 MG...
Hi, I am taking stats class and I have one question. I have been struggling with...
Hi, I am taking stats class and I have one question. I have been struggling with it for few hours. To investigate the fluid mechanics of swimming, twenty swimmers each swam a specified distance in a water-filled pool and in a pool where the water was thickened with food grade guar gum to create a syrup-like consistency. Velocity, in meters per second, was recorded and the results are given in a table below. The researchers concluded that swimming in guar...
I am working on extensive report for my Advanced Corp. Tax class and I am hoping...
I am working on extensive report for my Advanced Corp. Tax class and I am hoping to get a better understanding of the following: -In order for a corporation to make a valid “S” election, the corporation must be a “small business corporation.” Explain the meaning of “small business corporation” in this context. -Explain what ‘separately stated items’ are in regards to Partnerships and S corporations? Give an example of ‘separately stated items’ for each type of entity. -What requirements...
In my government class, I am required to write a letter to my U.S House of...
In my government class, I am required to write a letter to my U.S House of Representative (I’m located in Dallas, Tx) about either three social issue or three political issues we are facing. Can anyone help me out on how I should start my letter. How should I address my concerns.
Please write the program in JAVA and provide me with the output screenshots!! Assignment Objectives •...
Please write the program in JAVA and provide me with the output screenshots!! Assignment Objectives • Be able to write methods • Be able to call methods Introduction Methods are commonly used to break a problem down into small manageable pieces. A large task can be broken down into smaller tasks (methods) that contain the details of how to complete that small task. The larger problem is then solved by implementing the smaller tasks (calling the methods) in the correct...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT