0% found this document useful (0 votes)
235 views

CSC 201-Homework2

The document provides instructions for Homework 2 for a computer science course. Students are asked to write an algorithm and Java program to simulate a basic car rental reservation system that allows users to view available cars, reserve cars, and exit the system. The program should track car availability and only show available cars for reservation. Sample output and usage is provided.

Uploaded by

pavanil
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
235 views

CSC 201-Homework2

The document provides instructions for Homework 2 for a computer science course. Students are asked to write an algorithm and Java program to simulate a basic car rental reservation system that allows users to view available cars, reserve cars, and exit the system. The program should track car availability and only show available cars for reservation. Sample output and usage is provided.

Uploaded by

pavanil
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 5

CSC 201

Computer Science – I
Homework – 2
Out: Thursday, Oct 1st 2009
Due: Thursday, Oct 13th 2009

Instructions

1) All the Homeworks are individual assignments. No group work allowed.


2) Please submit a hard copy of the assignment before start of the class by 11:05
AM. If an assignment is due Tuesday, please submit it by 10:05AM (No
Exceptions).
3) Please include proper comments in your programs.
4) If it is a programming assignment, you would need to submit both electronic
copy (to [email protected]) and a hard copy. Same timings apply for
both the submissions.
5) Non-submission of homework electronically OR manually will result in a ‘0’
in that homework.
6) Please read and understand the Cheating Policy mentioned in the course
outline document.
7) Any questions/concerns should be directed to the Professor.
8) I recommend students to start working on the assignment as early as
possible.

Total: 50 Points
Question: Algorithm: 10 points Code/Program: 40 points

Write an algorithm and a Java Program for the below scenario:

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.

Scenario 1: View cars

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

Scenario 2: Reserve Car

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.

import scanner class;


Class carrental
{
public static void main(String[] args)
{

boolean[] available = { true, true, true };


String[] carname = { “car1”, “car2”, “car3” };

System.out.println(“Welcome to ABC Car Rental Company”);


System.out.println(“********************************”);
System.out.println(“Menu”);

System.out.println(“\n1. View Cars \n 2. Reserve Car \n 3. Exit “);

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*/);

System.out.println(“You have exited the system”);

Sample Run:

Welcome to ABC Car Rental Company


*********************************

MENU

1) View Cars
2) Reserve Cars
3) Exit
Please enter your option:
1

****************************

CAR NAME AVAILABILITY


AAA true
BBB true
CCC true
****************************

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

Please enter your option


1

****************************

CAR NAME AVAILABILITY


AAA true
BBB false
CCC true

****************************

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

Your car is reserved!

1) View cars
2) Reserve car
3) Exit
Please enter your option
1

****************************

CAR NAME AVAILABILITY


AAA false
BBB false
CCC true

****************************

1) View Cars
2) Reserve Car
3) Exit
Please enter your option:
3
You have exited the Car Rental system

______________________________ End ______________________________

You might also like