Professional Documents
Culture Documents
Elizabeth Aquino
Instructions:
1. Use this document template to report your answers and create separate java files
for your classes. Enter all lab partner names at the top of first page.
2. You don’t need to finish your lab work during the corresponding lab session.
3. ZIP your Java files and lab report into a single file. Name the file as follows:
LastName_FirstName_CS116_Lab5_Report.zip
4. Submit the final document to Blackboard Assignments section before the due
date. No late submissions will be accepted.
5. ALL lab partners need to submit a report, even if it is the same document.
Objectives:
1. (5 points) Design, code and test programs that require arrays.
2. (7 points) Design, code and test a user-defined object containing an array.
3. (8 points) Design, code and test a user-defined object containing an array.
Problem 1 [5 points]:
Write a program that:
asks the user how many exam scores there are (and verifies that the user
entered a positive integer),
prompt the user for each real-valued score, one by one (as shown below in
Sample program behavior / output: box),
1
Calculate and output the average of the scores and count and output how many
scores are greater than the average (as shown below in Sample program
behavior / output: box).
Your tasks:
Provide basic design of your program (inputs/outputs, their format, valid ranges,
etc. along with all necessary computation steps) in the box below [1 out of 5
points]:
Program design:
2
Complete the Test Plan table below (the number of test cases is up to you, but
should be fairly exhaustive) [1 out of 5 points]:
Test plan
Test case Sample data Expected result Verified?
Problem 2 [7 points]:
Write a DailySales class to store a collection of a company's daily sales records
for a single month (up to 31 days). All daily sales are of integer data type. You do
not have to worry about verifying the number of days actually in the month. Please
code a class with the following methods:
public int maxDay() - return the day number with the maximum sales,
Your tasks:
Provide basic design of your program (define the fields/attributes and methods,
include data type and valid ranges for attributes, and access control, arguments
and return types for methods) in the box below [1 out of 7 points]:
3
Program design:
public class DailySales {
Complete the Test Plan table below (the number of test cases is up to you, but
should be fairly exhaustive) [1 out of 7 points]:
Test plan
Test case Sample data Expected result Verified?
Days in month 32 Invalid-input Yes
message
Day number 32 Invalid day message Yes
Sales -1 Invalid sales message Yes
Problem 3 [8 points]:
This problem will explore some basic traits of an unsorted list of data. We will not go
to the extent of sorting the data, but try to understand some ideas leading to sorting.
Write a class, UnsortedData, that has two "public static" methods:
4
A method called countOutOfPosition that
prompts the user for a name of an input file (all the data files are in Blackboard
-> Class Notes -> Lab Code -> Lab #05 section),
reads 100 real numbers from that file. You can assume the file exists, and
contains 100 valid real numbers.
Then:
call "countOutOfPosition method and display the result.
call "bubble" and your first function again and see if there items are not as
far "out of position" as before.
Sample run:
Your tasks:
5
Complete the Test Plan table below (the number of test cases is up to you, but
should be fairly exhaustive) [1 out of 8 points]:
Test plan
Test case Sample Expected result Verified?
data
dataRando dataRando Total Out of Position BEFORE Bubble = 2604 Yes
m.txt m.txt
Total Out of Position AFTER Bubble = 2508
dataSorted. dataSorted. Total Out of Position BEFORE Bubble = 0 Yes
txt txt
Total Out of Position AFTER Bubble = 0
dataReverse dataReverse Total Out of Position BEFORE Bubble = 4950 Yes
Sorted.txt Sorted.txt
Total Out of Position AFTER Bubble = 4851
You can see with each run of Bubble, we are removing "Out of Position" counts
(except for the already sorted input of course). If we keep executing "Bubble", we
will eventually sort the data, this is called BubbleSort. The "Out of Position" count is
sort of a measure of how much work the sort needs to do on that input data set.
Make sure you add try-catch sections that handle FileNotFoundException where
appropriate.