# ITSC121S2020Lab8

## Eighth Programming Lab, ITSC 121, Spring 2020

### Overview

Write the following programs. The first one deals counting occurrences. The second deals with stats on scores. The third one deals with timing searches. The last is extra credit and deals with the command line.

#### Program 1: Counting occurrences (problem 7.3)

Write a program that reads in the integers between 1 and 100 and counts the occurrences of each. Assume the input ends with a 0. Here is a sample run of the program.
Enter the integers between 1 and 100: 2 5 6 5 4 3 23 43 2 0
2 occurs 2 times
3 occurs 1 time
4 occurs 1 time
5 occurs 2 times
6 occurs 1 time
23 occurs 1 time
43 occurs 1 time

Note if a number occurs more than one time, the plural word "times" is used in the output. A hint can be found here. If you use the hint (i.e. read it), you must document that fact in your write-up.

#### Program 2: Stats (problem 7.4)

Write a program that reads an unspecified number of scores and determines how many scores are above or equal to the average, and how many scores are below the average. Enter a negative number to signify the end of the input. Assume the maximum number of scores is 100.

#### Program 3: Timing (problem 7.16 adapted)

Write a program that randomly generates an array of 100,000 integers and a key. Estimate the execution time of each of the following:

1. invoking a linearSearch on the data unsorted via:
```    long startTime, endTime, executionTime;
startTime = System.nanoTime();
found = linearSearch(dataValues,key);
endTime = System.nanoTime();
executionTime = endTime - startTime;
System.out.print(exeuctionTime);
```
1. invoking a sort and then the linear search (get the separate time for each part)
2. invoking a sort and then the binary search (get the separate time for each part)

Answer the following questions in the write on this program (under lessons learned)

1. . Under what conditions (how many searches) do you think it would need to do to make it worth the time to sort first if you use the linear search?
2. . Under what conditions (how many searches) do you think it would need to do to make it worth the time to sort first if you use the binary search?

#### Program 4: command line (extra credit) (problem 7.21)

Write a program that passes an unspecified number of integers from the command line and displays their total.

### Reminders

1. Include proper comments for all
2. Use proper formatting, etc.
3. Test with more than one set of data where it is appropriate
4. Get the correct data outputted on the program before worrying about formatting

### Submissions

1. Create a software development report that includes the following for the program:
• A problem summary (the big picture) for each program
• A list of requirements for each program. (Things that this particular implementation of a solution must do)
• A list of steps each of your programs do
• A testing report for each program: What exact input you used and what output you got.
• How long it took to write it, and how much time was on it each day!
• Who you got help from (if you got help)
• Changes (if any) you would make if you had more time and/or skill
• At least two things you learned while writing the program(s)
2. Create a zip folder with your software development report(s) and your java file(s) and submit that to canvas.
3. Due date can be found on canvas