## CS 1401, Exam #3, 11:30 am version

Date: Friday, November 9, 2007
Name (please type legibly, ideally in block letters): ______________________________________________________________________

Exactly 40 years ago, on November 9, 1967, the "Rolling Stone" magazine was launched. It is still the main magazine to read about rock music, rock groups, and rock concerts. Rock music is usually not about computing, but when a group stages a concert, a lot of planning and computing is needed. Let us help them.

The profit produced by a concert can be computed as the revenue (ticket price (p) times number of seats (s)) minus expenses (e).

1a. Write a method named profit for computing the value p * s - e for given integer s and given real numbers p and e.

1b. Call (invoke) your method profit in the main method to compute the profit of a concert where each ticket costs \$50.00, 10,000 seats were sold, and the expenses were \$450,000.00. (You do not need to write the entire main method, just the part that assigns values to m and c and calls your method.)

1c. Trace, step by step, how the computer will perform the needed computations, and check that the result is indeed correct (should be \$50,000.00).

```

```
2a. Define a class Concert whose elements are concerts; each concert is characterized by its ticket price (in US dollars), the number of seats, and expenses (in US dollars). Your class should contain a constructor method, accessor methods, mutator methods, and a method for computing the concert's profit.

2b. Use your class in the main method to define a new object "elPasoConcert" of type Concert, at which each ticket costs \$50, 10,000 seats were sold, and the expenses were 450,000.00. Compute and print this concert's profit; then, assume that twice as many seats were sold, and compute and print the new value of the profit.

```

```
3a. Write a piece of code that, given an array p of ticket prices of different concerts, an array s containing numbers of seats, and the array e containing expenses, computes and prints the profits of different concerts.

3b. To check the correctness of the code you wrote in Part 3a, write a piece of code that defines arrays corresponding to 2 concerts:

• in the first, we have \$50 tickets, 10,000 seats, and \$450,000 in expenses;
• in the second, we have the same ticket price and the same expenses, but twice as many seats.

3c. Trace step-by-step how the piece of code you wrote in Part 3a will compute the corresponding profits. Hint: the profits are equal to \$50,000 and \$550,000.

```

```
4a. Write a method that, given an array s of numbers of seats at different concerts, finds the concert with the largest attendance.

4b. To check the correctness of your method, write a piece of code that defines a new array s consisting of 3 integers 10,000, 20,000, and 5,000.

4c. Trace step-by-step how the piece of code you wrote in Part 4a will find the concert with the largest attendance. Hint: the desired largest attendance concert is element No. 1, its attendance is

max(10,000, 20,000, 5,000) = 20,000.

```

```
5. Name main GUI components, and briefly explain their use.