Fall 2013, The College of Saint Rose

Lecture 19: Arrays
Date: Tuesday, November 26, 2013

Agenda

• Announcements
• Lecture 18 assignment recap
• Recap of ArrayLists
• Arrays
• In-class group exercise: we will work together to write a program that reads in a series of daily sales reports for a business, starting with a Sunday. The program will keep track of and display in graphical form, the maximum sales amount and overall average for each day of the week. The graphs should be updated after each day's sales are entered. We will assume a valid range of sales of 0-300 units per day.

Due at the start of class, Tuesday, December 3.

Please submit answers to these questions in Submission Box under "LA19" by the start of our next class. We will discuss these questions at the start of class, so no late submissions are accepted. Please be sure that your name is clearly indicated in all submissions.

1. What is the output when this method is executed? (8 points)
```private void doSomething() {

int [] report = { 5, 4, 10, 4, 6, 3, 4 };
int turn = 0;
int shot = 0;
int lastTotal = 0;

while (shot < report.length && turn < 10) {
int increment = report[shot] + report[shot+1];

if (increment >= 10) {
increment += report[shot+2];
}

if (report[shot] < 10) {
shot++;
}

lastTotal += increment;
shot++;
turn++;

System.out.println(shot + " : " + lastTotal);
}
}
```
2. Write a method that takes an ArrayList of Integer values as its parameter and returns the sum of all elements in the array. (4 points)
3. Write a method that takes an array of double values as its parameter and returns the sum of all elements in the array. (4 points)

Examples