csc 201-homework3
TRANSCRIPT
-
8/14/2019 CSC 201-Homework3
1/8
CSC 201
Computer Science I
Homework 3
Out: Sunday, Nov 1st 2009Due: Sunday, Nov 15th 2009
Instructions
1) All the Homeworks are individual assignments. No group work allowed.
2) This electronic version of this assignment is due Nov 15th
10:00AM(Sunday).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
Programming Assignment 3 simulates Java Classes. For the below assignment welearn to create/design our own data type.
Write an algorithm and aJava Program for the below scenario:
We simulate a Car Reservation System where in users 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.
There are two types of customers: Preferred (P) and Normal Customers (N).
-
8/14/2019 CSC 201-Homework3
2/8
Scenario 1: View cars
When either user (Preferred or Normal customers) enters option 1, he can view a list ofall the cars and their availability. Your output should look something like below.
Car Name Availability MemberCodeCar1 True P
Car2 True P
Car3 True NCar4 True N
The carName variable is of datatype String.
The availability variable is of data type Boolean.The MemberCode variable is of datatype String.
Scenario 2: Reserve Car
When either user enters option 2, user has the ability to reserve a car. But a normal
customer with member code = N cannot reserve a car whose member code = P.A preferred customer can reserve cars with either of the member code i.e P or N.
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 car
{bavailability;
String member_code;
String car_name;
car(String name, String code){
}
-
8/14/2019 CSC 201-Homework3
3/8
boolean getAvailability(String name)
{
}
public String getCarName()
{
}
public String getMemberCode(){
}
void displayAllCars()
{
}
void reserveCars(String name)
{
}
}
Class carrental
{
public static void main(String[] args){
System.out.println(Hello, Welcome to ABC car Rental company);
Scanner s = new Scanner(System.in);
car[] carobj = new car[3];
// Students are encouraged to take a sample of more than 10 cars
-
8/14/2019 CSC 201-Homework3
4/8
//Initializing the car objects in below code
//The availability for all cars is true initially.//You can initialize P or N according to your wish.
carobj[0] = new car("car1","P");carobj[1] = new car("car2","P");
carobj[2] = new car("car3","N");
System.out.println("Enter your code P:For Preferred Customers or N: For
normal customers.");
String code = s.next();if(code.equalsIgnoreCase("N"))
{
System.out.println("Welcome customer.");
while(true){
System.out.println("Here are your options:1.ViewCars\n2.Reserve a car\n3.Exit");
// Please fill in the code when a normal customer enters above//options
}}
else
if(code.equalsIgnoreCase("P")){
System.out.println("Welcome preferred customer:");
while(true){
System.out.println("Here are your options:1.View
Cars\n2.Reserve a car\n3.Exit");
-
8/14/2019 CSC 201-Homework3
5/8
// Please fill in the code when a preferred customer enters above
//options
}
}
}}
Sample Run:
run: When a preferred customer wants to operate this system.
Hello welcome to ABC car companyPlease enter num of cars to operate on
3Enter your code P:For Preferred Customers or N: For normal customers.
P
Welcome preferred customer:
Here are your options:1.View Cars
2.Reserve a car
3.Exit
1
CarName Avail Member-Codecar1 true P
car2 true P
car3 true N
Here are your options:
1.View Cars
2.Reserve a car3.Exit
2
Choose car name
car1
Your car is reserved
Here are your options:
1.View Cars
-
8/14/2019 CSC 201-Homework3
6/8
2.Reserve a car
3.Exit
2
Choose car namecar3
Your car is reservedHere are your options:
1.View Cars
2.Reserve a car
3.Exit
1
CarName Avail Member-Code
car1 false P
car2 true Pcar3 false N
Here are your options:
1.View Cars
2.Reserve a car
3.Exit3
You have exited the system!
BUILD SUCCESSFUL (total time: 38 seconds)
Sample Run: For a Normal Customer
run:Hello welcome to ABC car company
Please enter num of cars to operate on
3Enter your code P:For Preferred Customers or N: For normal customers.
N
Welcome customer.Here are your options:
1.View Cars
2.Reserve a car
-
8/14/2019 CSC 201-Homework3
7/8
3.Exit
1
CarName Avail Member-Code
car1 true Pcar2 true P
car3 true N
Here are your options:
1.View Cars
2.Reserve a car3.Exit
2
Enter a car name to reserve:
car1
Preferred Car: Sorry, You cannot reserve a preferred customer car!!
Here are your options:
1.View Cars2.Reserve a car
3.Exit
2
Enter a car name to reserve:car3
Your car is reserved
Here are your options:
1.View Cars
2.Reserve a car
3.Exit
1
CarName Avail Member-Code
car1 true P
car2 true P
-
8/14/2019 CSC 201-Homework3
8/8
car3 false N
Here are your options:
1.View Cars2.Reserve a car
3.Exit
3You have exited the system!
BUILD SUCCESSFUL (total time: 28 seconds)
_______________________________________________________________________