|
|
|
 |
 |
 |
|
Tollbooth Programming Series
|
|
|  |
by Leigh Ann Sudol Fox Lane High School Bedford, New York
 |
|
|  |
More Nifty Assignments...
Assignments
Tollbooth Version 1 (Methods and return Statements)
The Port Authority of New York and New Jersey wants to create a data storage object that counts cars and accumulates the amount of money collected by a tollbooth operator. The object needs to have accessor methods that will return the values it stores. It also needs a method that simulates the car traveling through the tollbooth and adjusts the values accordingly.
Download tollbooth.java and fill in the private member data as well as the methods provided. Use tollboothDisplay.java to test your code. (When you click on the applet, another car travels through the tollbooth.)
tollbooth.java.zip
tollboothDisplay.java.zip
Tollbooth Version 2 (Inheritance)
The Port Authority has decided on using an electronic payment method (E-ZPassSM) in some of their tollbooths. The tollbooths that accept an E-ZPass cannot accept a paying car. Add functionality to the tollbooth class from Tollbooth Version 1 so that the tollbooth counts the number of E-ZPass cars that have traveled through the tollbooth.
Download the ezTollboothOnly.java file and fill in the private member data as well as the methods provided. Modify the tollboothDisplay.java file from Tollbooth Version 1 so that it displays information about the number of E-ZPass cars and tests your new object.
ezTollboothOnly.java.zip
Tollbooth Version 3 (Decision Structures)
The Port Authority has requested that the tollbooth be able to take either E-ZPass cars or paying cars and adjust their state variables accordingly. Paying cars will increment the number of cars and the amount of money collected. E-ZPass cars will increment the number of cars and the number of E-ZPass cars. (Since no physical money is collected from E-ZPass cars, they will not add to the amount of money collected.)
The car itself needs to keep track of whether or not it has an E-ZPass tag. Therefore we will need to add a car object to our simulation. This version will have two assignments as part of it.
Assignment 1: Download the car.java data storage object and use a Boolean value to keep track of whether or not the car contains an E-ZPass.
car.java.zip
Assignment 2: Download the dualTollbooth.java file and fill in the private member data as well as the methods provided. Modify the tollboothDisplay.java file from Tollbooth Version 1 so that it displays the same information as before, plus the number of cars that were not E-ZPass carriers. (Extension: Use a random number generator to determine if a car carries an E-ZPass tag -- it can be placed either in a default constructor or in the onMouseClick method.)
dualTollbooth.java.zip
Tollbooth Version 5 (Looping Structures/Random Numbers)
The Port Authority has decided that they would like to model an average day in the tollbooth. In order to do this, they have determined that a car has a one-in-three chance of carrying an E-ZPass tag. Their studies have also shown that on average 2,400 cars travel through the tollbooth every day (busy road). They would like you to modify your program so that instead of one car per click of the mouse, it models an entire day with a click of the mouse.
Modify your tollboothDisplay.java file so that it uses a looping structure to model 2,400 cars traveling through the tollbooth. Use a random number generator to decide if each car will have an E-ZPass tag (separate decision for each car).
Tollbooth Version 6 (for Loop Structure, Using the add() Method of ArrayList)
The Port Authority has decided that its one tollbooth is backing up traffic too much on the road, and it needs to add some more tollbooths to the toll plaza. The toll plaza should maintain this list of tollbooths (they are a list because each tollbooth is in a specific place in the plaza and could be numbered).
Download the tollplaza.java file and implement the methods given. Use the tollplazaDisplay.java file to test the results of your coding.
tollplaza.java.zip
tollPlazaDisplay.java.zip
Tollbooth Version 7 (while loop structure, sum/average algorithms, iterators)
The Port Authority has decided that individual numbers from each tollbooth do not matter. They wish to see a program that calculates the total number of cars that pass through the booths, the total number of E-ZPass cars that pass through the booths, and the total amount collected by the tollbooth workers. They also would like an average amount collected by the tollbooth workers for the day.
Download the tollPlazaWithStatistics.java file and implement the methods given. Modify the tollPlazaDisplay.java file to show the results from the statistical calculations added to the new object.
tollPlazaWithStatistics.java.zip
tollPlazaDisplay.java.zip
Tollbooth Version 8 (indexing ArrayList with get() method)
The Port Authority (deciding that it has paid you enough money and now wants one last modification) has requested a load manager system for its toll plaza. The traffic has gotten steadily worse since the original program, and cars are now backing up at one tollbooth or another. You are to study two traffic patterns, and the resulting statistics are to be displayed. For both traffic patterns, the Port Authority wishes to view the number of the tollbooth with the most cars, the number of the tollbooth with the least cars and view a bar graph drawn on the screen (different-sized rectangles) that displays the distribution of cars through the plaza.
Traffic Pattern 1: Cars are randomly assigned to a specific tollbooth within the toll plaza itself.
Traffic Pattern 2: Cars are randomly assigned to a specific tollbooth within the toll plaza; however, they have a greater chance of choosing the center three lanes.
Download the trafficPattern.java file and implement the methods provided.
TrafficPattern.java.zip
Modify the tollPlazaDisplay object to meet the requirements specified above. It is up to you to decide where to place the functionality for the following:
- Where a car is assigned to a specific tollbooth and how that booth's number is communicated to the plaza
- Whether to implement the two traffic patterns at the same time, or in separate programs
Be prepared to discuss the following:
- Why did you choose your implementation for the above functionality?
- Which of the two traffic patterns appears to be better if all lanes travel just as quickly?
- Which of the two traffic patterns appears to be better if the center lanes are able to merge back into traffic more rapidly than the outer lanes?
Teacher's Comments
This series of programming assignments is designed to teach using good object-oriented design techniques in a large, complex system, without having to give an assignment that has a large time span at any one given time. The versions above slowly build into a complex system through a variety of units of study, increasing slowly in difficulty as well as complexity of the entire system.
Contribute
If you would like to contribute your suggestions for nifty assignments, please submit your ideas.
|
|
|
|
|
|