Csc 201-homework3

  • June 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Csc 201-homework3 as PDF for free.

More details

  • Words: 879
  • Pages: 8
CSC 201 Computer Science – I Homework – 3 Out: Sunday, Nov 1st 2009 Due: Sunday, Nov 15th 2009

Instructions 1) 2) 3) 4) 5) 6) 7) 8)

All the Homeworks are individual assignments. No group work allowed. This electronic version of this assignment is due Nov 15th 10:00AM(Sunday). Please include proper comments in your programs. 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. Non-submission of homework electronically OR manually will result in a ‘0’ in that homework. Please read and understand the Cheating Policy mentioned in the course outline document. Any questions/concerns should be directed to the Professor. 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 we learn to create/design our own data type. Write an algorithm and a Java 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).

Scenario 1: View cars When either user (Preferred or Normal customers) enters option ‘1’, he can view a list of all the cars and their availability. Your output should look something like below. Car Name Car1 Car2 Car3 Car4

Availability True True True True

MemberCode P P N 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) { }

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

//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.View Cars\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");

// 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 company Please enter num of cars to operate on 3 Enter 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 car1 car2 car3

Avail Member-Code true P true P true N

Here are your options: 1.View Cars 2.Reserve a car 3.Exit 2 Choose car name car1 Your car is reserved Here are your options: 1.View Cars

2.Reserve a car 3.Exit 2 Choose car name car3 Your car is reserved Here are your options: 1.View Cars 2.Reserve a car 3.Exit 1 CarName

Avail Member-Code

car1 car2 car3

false true false

P P N

Here are your options: 1.View Cars 2.Reserve a car 3.Exit 3 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 3 Enter 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

3.Exit 1 CarName

Avail Member-Code

car1 car2 car3

true true true

P P N

Here are your options: 1.View Cars 2.Reserve a car 3.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 Cars 2.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 car2

true true

P P

car3

false

N

Here are your options: 1.View Cars 2.Reserve a car 3.Exit 3 You have exited the system! BUILD SUCCESSFUL (total time: 28 seconds) _______________________________________________________________________

Related Documents

Csc
May 2020 19
Csc
October 2019 31
Csc
November 2019 34
Csc Bpo
November 2019 24
Firmenvorstellung Csc
June 2020 9
Audio Csc
November 2019 22