|
Fundamental Programming Concepts
Summer 2000 |
|
Overview | ||||||||||||||||||
This lab requires the use of:
As the size of your programs grows, you will find that you need to use the same (or very similar) code in more than one place in a program. When this occurs, you should create a separate method that is called each time you need the code. You should not cut and paste the code into your program in several different places -- this leads to poor maintainability. We will penalize duplicated code when we see it.
|
||||||||||||||||||
Part I: TimeTester | ||||||||||||||||||
Create a class called Time according to the specification given below -- read carefully! Also write a driver program, called TimeTester, to test your class. This will be a more complicated Metrowerks project than you've created so far. You'll have to add two source files to it (Time.java and TimeTester.java). Your main method will go in TimeTester -- Time will not have a main method. You only need to import CS99 into the files in which you use Console methods, which will either be just TimeTester (if you use console input in your testing), or no files. Each of your classes should have a header comment. The Driver ProgramA driver program is a program that is used to test the functionality of classes and methods. For your driver program, you should test all of the methods in the Time class to make sure they work correctly in all cases. When we test your classes, we will substitute our own driver program for yours. This means two things for you:
The Time ClassThis class represents military time to the precision of seconds. Military time does not use AM or PM; instead, it uses hours from 0-23. So in military time midnight is 00:00:00, whereas in standard time midnight is 12:00:00 AM. Military time always uses two digits for hours, minutes, and seconds. Standard time uses the minimum number of digits for hours (either one or two), but always uses two digits for minutes and seconds (e.g., 5:00:00 PM). The Time class should have the following public methods (none should be static):
It should have at least the following private fields (none should be static):
You may also use any other private methods and fields you wish in implementing the above specification. Hints:
|
||||||||||||||||||
Part II: Airline | ||||||||||||||||||
Create an airline reservation program. The program is for a
small company with only one airplane. The plane has just 8 seats numbered
1-8. Passengers may only reserve seats on the current flight (i.e., they
cannot make reservations in advance). The airline wants the program to
allow them to make reservations, cancel reservations, and print a seating
chart for the current flight. When making a reservation, the only
information the airline needs is the passenger's name. Passengers are
automatically assigned the next available seat and may not request a
particular seat. The assigned seat should be output as part of the
reservation process. Reservations are canceled by seat number, not by
passenger name.
Your program should be menu-based. For example, the main menu for the program might look like:
Use an array of strings to represent the airplane. Each element is a seat, and is either equal to the passenger's name (if the seat is reserved), or the empty string. Be sure to read section 6.2 for information about arrays of objects. In particular, you must not only declare and create the arrays of seats, but you must also create each of the strings in the array. See the hint below. You may use static fields only if they are also final (in other words, class-wide constants). For example, you could create a constant that represents the number of seats on the plane. In particular, your array of seats may not be static. Hints:
|
||||||||||||||||||
Submitting | ||||||||||||||||||
Submit exactly the following:
|