Lab 03
A Below Average Winter
Objective:
Write a program that takes in temperatures for 10 days and
stores it in an array. Find the average temperature for those 10 days, and
then print the number of days and the temperatures that were strictly below the
average.
Lab Solution
Requirements:
- Functionality. (80pts)
- No Syntax, Major Run-Time, or Major Logic Errors.
(80pts*)
- *Code that cannot be compiled due to syntax errors is
nonfunctional code and will receive no points for this entire section.
- *Code that cannot be executed or tested due to major
run-time or logic errors is nonfunctional code and will receive no
points for this entire section.
- Only use Arrays to store the collection. (80pts*)
- *Any other data structure such as LinkedLists,
ArrayLists, etc. will result in no points awarded for this entire
section.
- Clear and Easy-To-Use Interface. (20pts)
- Users should easily understand what the program does and
how to use it.
- Users should be prompted for input and should be able to
enter data easily.
- Users should be presented with output after major
functions, operations, or calculations.
- All the above must apply for full credit.
- Inputting the Temperatures. (20pts)
- The user must be able to enter the 10 temperatures.
- These temperatures must be stored in an Array of a
decimal type.
- All the above must apply for full credit.
- Finding the Average. (20pts)
- Once the temperatures have been entered, the average
temperature must be calculated and displayed.
- The average is the sum of all of the values in the Array
divided by the size (or length) of the Array.
- All the above must apply for full credit.
- Printing All Temperatures Below the Average. (20pts)
- Once the average has been calculated, the program must
display all temperatures that are strictly below the average.
- If there are no temperatures strictly below the average,
then the program should display nothing.
- Coding Style. (10pts)
- Readable Code
- Meaningful identifiers for data and methods.
- Proper indentation that clearly identifies statements
within the body of a class, a method, a branching statement, a loop
statement, etc.
- All the above must apply for full credit.
- Comments. (10pts)
- Your name in the file. (5pts)
- At least 5 meaningful comments in addition to your name.
These must describe the function of the code it is near. (5pts)
Example Dialog:
Welcome to the below average temperature tester program.
Please enter the temperature for day 1
33.0
Please enter the temperature for day 2
20.0
Please enter the temperature for day 3
41.0
Please enter the temperature for day 4
48.0
Please enter the temperature for day 5
60.0
Please enter the temperature for day 6
51.0
Please enter the temperature for day 7
29.0
Please enter the temperature for day 8
71.0
Please enter the temperature for day 9
63.0
Please enter the temperature for day 10
66.0
The average temperature was 48.2
The days that were below average were
Day 1 with 33.0
Day 2 with 20.0
Day 3 with 41.0
Day 4 with 48.0
Day 7 with 29.0
Solution Tests:
- Is your name written as a comment in all source files?
- Does the solution compile (no syntax errors)?
- Given the input <33.0, 20.0, 41.0, 48.0, 60.0, 51.0,
29.0 71.0, 63.0, 66.0> does the program print out:
The average temperature was 48.2
The days that were below average
were
Day 1 with 33.0
Day 2 with 20.0
Day 3 with 41.0
Day 4 with 48.0
Day 7 with 29.0
- Given the input <10.0, 20.0, 30.0, 40.0, 50.0, 60.0,
70.0, 80.0, 90.0, 100.0> does the program print out:
The average temperature was 55.0
The days that were below average
were
Day 1 with 10.0
Day 2 with 20.0
Day 3 with 30.0
Day 4 with 40.0
Day 5 with 50.0
- Given the input <10.0, 10.0, 10.0, 10.0, 10.0, 10.0,
10.0, 10.0, 10.0, 10.0> does the program print out:
The average temperature was 10.0
The days that were below average
were
Lab Report
- Create a section named “Problem” and describe this lab’s
problem in your own words. (10pts).
- Create a section named “Solution Description” and describe
how the code solves the problem in your own words. (10pts).
- Create a section named “Problems Encountered” and describe
the various syntax, run-time, and logic errors that were encountered while
implementing the solution. (10pts).
- Draw a flow chart to solve this problem in the proposed
solution section.
- Are arrays able to change size as in grow or shrink
length?
- What is the last valid index in an array with a given
length?
- Given the following code snippet, are there any kind of
errors? If so, name the types, where, and how this code can be fixed.
Otherwise, what does this code print to the console?
- Given the following code snippet, are there any kind of
errors? If so, name the types, where, and how this code can be fixed.
Otherwise, what does this code print to the console?
- Given the following code snippet, are there any kind of
errors? If so, name the types, where, and how this code can be fixed.
Otherwise, what does this code print to the console?
- Given the following code snippet, are there any kind of errors?
If so, name the types, where, and how this code can be fixed. Otherwise,
what does this code print to the console?
Finally:
Upload the source code (.JAVA File Extension) and written
lab report (.DOC, .DOCX, or .PDF file extension) to the CSCE Dropbox.