# Working with arrays

• Goal of lab

• Get familiar with arrays

• Preparation

```   mkdir ~/cs170/lab10                    # make lab directory
cd /home/cs170001/share/labs/lab10     # Go to share folder with lab10
cp * ~/cs170/lab10                     # Make a copy to your folder
cd ~/cs170/lab10                       # Go back to your lab folder
```

• If you use BlueJ

• If you are using BlueJ for the lab, you must open lab10 as "Non BlueJ"

• Preliminaries

• We have seen the ItemDataBase.java example program in class.

• Relevant material:

The notes on searching for someone will help you a lot in doing this lab.

• Lab assignment

• Edit the program file ItemDataBase.java and write a method findOldest() that returns a string containing the

• Name
• Phone
• Age

of the oldest person in the database.

Please: do NOT print the name, phone and age inside the findOldest() method.

In other words: do NOT use System.out.print() inside findOldest().

You need to use return(...) to return a string that contains the name, phone and age.

You can concatenate the name, phone and age together into one string using the "+" operator !

• Algorithm to find the maximum value (age)

• Was discussed before, in fact, it's a classic algorithm. See ths class note page that uses this algorithm: click here

• Look for "Array Algorithm 1: Find Max (8.5.3 in book)" and " Array Algorithm 3: Find the Rectangle with the largest area"

• You need to adapt the algorithm to find the largest age.

• In order to obtain the age of the ith item in the database, use: data[i].getAge()

• Testing

• Compile with:
```	javac DataBaseTest.java
```
• Run program with:
```        java DataBaseTest
```
• The correct output is:
```	A database of 100 data records has been created
# items stored in data[] is 19
Jack    123-4567        34
Jill    652-8723        12
Jake    763-8736        54
Robert  451-9283        34
John    763-8263        44
Helen   451-7333        13
Eli     456-8734        66
Dora    763-9283        52
Abe     456-8273        23
Bett    763-9123        72
Cathy   451-8273        23
Harry   763-8273        27
Karen   451-9134        62
Quinn   451-8722        34
Peter   456-9822        28
Paul    763-0988        37
James   777-9811        63
Wald    763-8812        44
Helen   777-9272        54

The oldest person in database is: Bett  763-9123        72
```

• Turn in:

• Turn in your ItemDataBase.java file before 6 PM using the commands:
```	cd ~/cs170/lab10

/home/cs170001/turnin  ItemDataBase.java  lab10
```