CSC 201-Homework2
CSC 201-Homework2
Computer Science – I
Homework – 2
Out: Thursday, Oct 1st 2009
Due: Thursday, Oct 13th 2009
Instructions
Total: 50 Points
Question: Algorithm: 10 points Code/Program: 40 points
We simulate a Car Reservation System where in a user of this system can check the
availability of a car and reserve it. The end-user will be presented with 3 options:
1) View cars 2) Reserve car 3) Exit the system.
When the user enters option ‘1’, he can view a list of all the cars and their availability.
Your output should look something like below.
Car Name Availability
Car1 True
Car2 True
When user enters option ‘2’, user has the ability to reserve a car. A list of all available
cars is displayed to the user. This means the cars that are already reserved should not be
displayed. When user reserves a car, the availability variable becomes False.
Scenario 3: Exit
When user enters option ‘3’, just break out from the system and your program should end
running.
_______________________________________________________________________
_
Below is the skeleton I have designed. Students are free to design their own program.
do
{
// Scanner class to accept user input.
//accept input from the user
if(input == 1)
{
System.out.println(“ CAR NAME AVAILABILITY”);
// Print out the cars and their availability. Write your code here.
}
else
if(input == 2)
{
System.out.println(“ Please enter the car number to reserve a car”);
// display the available cars for the user.
// If the car is not available i.e if the Boolean variable available
is //‘False’ do not print that car.
// If the car is available reserve that car by the setting the available
//variable.
else
if(input == 3)
break;
}while( /*condition*/);
Sample Run:
MENU
1) View Cars
2) Reserve Cars
3) Exit
Please enter your option:
1
****************************
1) View Cars
2) Reserve Car
3) Exit
Please enter your option:
2
You want to reserve the cars: Please enter car num to reserve
0 AAA
1 BBB
2 CCC
1
Your car is reserved!
1) View cars
2) Reserve car
3) Exit
****************************
****************************
1) View Cars
2) Reserve Car
3) Exit
Please enter your option:
2
You want to reserve the cars: Please enter car num to reserve
0 AAA
2 CCC
0
1) View cars
2) Reserve car
3) Exit
Please enter your option
1
****************************
****************************
1) View Cars
2) Reserve Car
3) Exit
Please enter your option:
3
You have exited the Car Rental system