## CS 1401 Assignment #5

Date Assigned: Thursday, September 29, 2005 or Friday, September 30, 2005.

Due Date: correspondingly, Thursday, October 6, 2005, or Friday, October 7, 2005, before the beginning of your lab section.

Goals: to learn mathematical functions like exp(x), log(x), conditions, and logical expressions.

Points: This assignment is worth a total of 20 points. No late assignments will be accepted, but credit will be given for partially completed assignments turned in on time.

Assignment: To celebrate latest football victories, CS students decided to follow the good old tradition of soaking each other with the drinks at the CS parking lot. The problem is that this creates a fertile ground for bacteria. To avoid an epidemic, we must clean up as soon as the bacteria concentration reaches the danger level D=0.97. To help, we need to design a software tool that would predict the bacteria contamination at the parking lot.

For each celebration, we know the time t of the celebration, we know the initial concentration C, and we know the rate a with which bacteria multiply. This means that if there was no cleanup, then at time T, the concentration is equal to C(T) = C * exp(a*(T-t)). If this predicted concentration exceeds the danger level D, this means that there was a cleanup, so the resulting concentration is C(T) = 0. In this case, we must return not only the resulting concentration level (C(T) = 0), but also the time c when the cleanup occurred. This time can be found from the equation C * exp(a*(c-t)) = D, i.e., as c = t + (1/a) * ln(D/C).

Structure: Define a class ParkingLot in which each object (parking lot) is characterized by two parameters: the bacteria concentration C and the rate a with which bacteria multiply. Make sure that your description includes:

• a constructor,
• two methods that return the values of the parameters, and
• two methods that update the values of the parameters.

Define a class Celebration in which each object (individual celebration) is characterized by its initial state (an object of type ParkingLot) and celebration time t. This class should include the following methods:

• a method that returns the initial state;
• a method that returns the celebration time;
• a method that updates the initial state;
• a method that updates the celebration time;
• a method that, given the time T, uses the above conditional descriptions to return the state of the parking lot at the time T (a state is an object of type ParkingLot);
• a Boolean-valued method that, given the time T, checks whether there was a cleanup;
• a method that, given the time T, determines the time of a cleanup.
Named constants such as the danger level D should be defined in the class Celebration.

All readings from the user and all printing to the screen should be in the main method of the application class.

The application class should do the following:

• ask a user for the original concentration of bacteria, and for the bacteria growth rate;
• based on the answer, construct the corresponding object of type ParkingLot;
• ask a user for the celebration time;
• based on the answer, construct the corresponding object of type Celebration;
• ask the user for the current time;
• use the methods defined for the above objects to print a message that describes:
• the current concentration,
• whether there was a cleanup, and
• if there was a cleanup, when exactly.

Deliverables: as announced in the labs.