Assignment #21

Instructions

  1. Write a Java program that does the following:
    1. In the main() method, complete Class Exercises 1, 2 and 3 from the lecture slides.
    2. Also, in the main() method, complete the following:
    3. Loop up at least 7 times, so your program can ask the user to enter the 7 high temperature of the week (whole numbers or decimals numbers, Fahrenheit or Celsius - up to you).
    4. Within the loop, ask the user to enter one high temperature.
    5. Within the loop, store each temperature in your array.
    6. If the user enters a temperature below absolute zero, then use an if statement to display an error message and keep looping. You might need to adjust the counter (index) in your for-loop, so you can repeat the same counter (index).
      For example: index=index-1;
    7. If the user enters non-numeric data, then use try/catch blocks to display an error message and keep looping. You might need to adjust the counter (index) in your for-loop, so you can repeat the same counter (index).
      For example: index=index-1;
    8. After the loop, display all the high temperatures in your array.
    9. Also display the average of the high temperatures.
  2. Don't forget to include Java documentation (javadoc) comments in your program. See the Java Coding Standard for details.
  3. See the syllabus for the Assignment Grading Guidelines for your program assignments.

Example Input and Output (I/O)

Array elements of INSTANTIATED array: null, null, null, null, null, null, null, 

Array elements of INITIALIZED array: 81.0, 81.5, 82.0, 82.5, 83.0, 83.5, 84.0, 

Enter the 7 high temperatures for each day of the past week.

Enter high temperature #1: 81.1
Enter high temperature #2: 95.5
Enter high temperature #3: 89.9
Enter high temperature #4: -500.5
ERROR: -500.5 is below absoute zero!
Enter high temperature #4: 85.5
Enter high temperature #5: 86.6
Enter high temperature #6: eighty eight point eight
ERROR: eighty eight point eight is not a number!
Enter high temperature #6: 88.8
Enter high temperature #7: 80.0

Your high temperatures are: 81.1, 95.5, 89.9, 85.5, 86.6, 88.8, 80.0, 
Average of high temperatures: 86.77142857142857

Click to validate the HTML code

Click to validate the CSS code