Question: I need help wring a code in the JAVA complier in netbeans for the following. It is for Chapter 2 of the How to program
I need help wring a code in the JAVA complier in netbeans for the following. It is for Chapter 2 of the How to program Java book.
This program should calculate the average customer rating.
Read 4 ratings
Calculate the average
Print the average
Print whether the average is Excellent, Good, Average, Bad, or Horrible.5 is Excellent, 4 is Good, 3 is Average, 2 is Bad, and 1 is Horrible.
Requirements:
Put System.out.println() after you finish the 4 calls to nextInt().This will help you match the Test Program and make it easier to use it.
Only use int variables for the reading and calculations.Integer division truncates.If the 4 ratings were: 4 4 3 4
The average is (4 + 4 + 3 + 4) / 4 = 3.75.But if you use int variables, you will only get 3 for your answer because of truncation.
We would like to round, so if you get 3.75, we really want to say the average is 4, not 3.
Math to the rescue!You can add 2 to the sum before you divide and it will do the rounding for us.Calculate the average as (4 + 4 + 3 + 4 + 2) / 4 = 4.25.Now when it truncates, the answer will be 4 instead of 3.
You should not need 4 different variables for the ratings.Remember you can change the value stored in a variable.Also, you can put additional lines of code between each call to nextInt()
Sample Run #1: (the highlighted text is what the user types)
4 ratings? 1 1 1 1
Rating is 1 - Horrible
Sample Run #2: (the highlighted text is what the user types)
4 ratings? 1 2 1 2
Rating is 2 - Bad
Sample Run #3: (the highlighted text is what the user types)
4 ratings? 3 3 3 4
Rating is 3 - Average
Sample Run #4: (the highlighted text is what the user types)
4 ratings? 4 4 4 4
Rating is 4 - Good
Sample Run #5: (the highlighted text is what the user types)
4 ratings? 5 4 5 4
Rating is 5 - Excellent
Extra Notes:
Did you correctly name the package/folder?
Did you correctly name the class/file?
Did you include comments?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
