CS 178 Programming with Multimedia Objects

Fall 2004

Recitation Exercise:

Prepared by: Aditya Mathur.

To be completed , as much as possible, in class on Oct 8, 2004.

Learning objectives:
  1. How to perform simple operations on arrays.
  2. How to use loops.
  3. How to write and use your own methods.
Complete the following set of instructions to develop a few simple methods. Note that we are NOT writing an applet. Instead, we are writing methods that could be used later inside a Java applet.

Array and other declarations:

  1. Declare an array planetNames to contain names of planets. Initialize the array to contain the following names: Mars, Earth, Jupitor, in that order.
  2. Declare another array named distance and initalize it to contain the distances of the planets mentioned above from the Sun. The distances (in thousands of Km) in the order of planets given above: 227940, 149600, and 778330.

For each of the following methods, you will need to decide on the parameter type and the return value type.

findAverage method:

  • Write a method that calculates and returns the average of all distances in planetName.

findMax method:

  • Write a method that returns the maximum of the distances in planetName

findMin method:

    • Write a method that returns the mainimum of the distances in planetName

sortDist method

  • Write a method to sort the planetNme array in the order of increasing distances.

Last update: October 6, 2004