628
Programming Warm-Up Exercises
1.Using the declarations in Exam Preparation Exercise 1, write code fragments
to do the following tasks. Assume sport 0 is football, 1 is basketball, and 2 is
volleyball.
a.Determine which school spent the most money on football.
b.Determine which sport the last school spent the most money on.
c. Determine which school had the most students playing basketball.
d.Determine in which sport the third school had the most students participat-
ing.
e.Determine the total amount spent by all the schools on volleyball.
f. Determine the total number of students who played any sport. (Assume that
each student played only one sport.)
g.Determine which school had the most students participating in sports.
h.Determine which was the most popular sport in terms of money spent.
i. Determine which was the most popular sport in terms of student participa-
tion.
2.Examine the following documentation of a class:
public classTwoDimensions
{
// Private data
private int[][] data;
private introwsUsed; // Number of rows that contain data
private intcolumnsUsed; // Number of columns that contain data
// Methods
publicTwoDimensions(intmaxRows, intmaxColumns)
// Constructor: creates a maxRows x maxColumns array
public voidinputData(BufferedReader inFile)
// Reads data into the array
// Data are on the file as follows:
// First line: number of rows (rowsUsed)
// Second line: number of columns (columnsUsed)
// Data are stored one value per line in row order.
// That is, the first columnsUsed values go into row 0; the
// next columnsUsed values go into row 1; etc.
public voidprint(PrintWriter outFile)
// Prints the values in the array on outFile, one row per line