Array

October 23, 2007

Turn in Outlab

First turn in your outlab from last week. Your TA will tell you how they want you to turn in your source code. Remember the .java file is your source code, do not give us your .class files.

To Do:

Today you will be creating two classes, one will be the driver and the other will hold your array and methods. In today's assignment you will be defining and initializing an array and writing several methods to manipulate the array. First: You have finished part one.

Part two:
Write a method to print the array in reverse order.

Part three
Write a method to print out the second largest element in the array.

Part four
Write a method to print the average of the array.

Part five
Write a method to search the array for an integer the user gives you.

Part six (a little harder)
Create a histogram according to your array data
If you array looks like this 1,2,3,1,2,3,3,2,1,1
Your histogram would look like this:
 *
 **
 ***
 *
 **
 ***
 ***
 **
 *
 *

Part seven (they're getting harder):
Write a method to print the frequency of each integer in the array:
e.g.: If you array has the elements 2,3,2,4,2,4,2,5,4,5
You would print out:
  The number 2 is in the array 4 times
  The number 3 is in the array 1 times
  The number 4 is in the array 3 times
  The number 5 is in the array 2 times
Hint: I showed you an example in class, and the book has a similar example.

Outlab

There is an outlab due next week.