Question
You will write a program to run a car rental shop. The program will work as follows: On startup, it will read a file of
You will write a program to run a car rental shop.
The program will work as follows:
On startup, it will read a file of Cars, staff, and customers (storing each into a single array, so you should have 3 arrays when you read everything).
It will then display a menu of choices, allowing staff to repeatedly select the choices.
When the staff chooses to quit the program, it will first write out the arrays back to the files it read it from. Meaning cars will be written out to cars.txt and customers will be written back to custoerms.txt.
Simplifying assumptions:
We will assume a maximum of 100 cars, customers. We will not allow for the possibility of needing to increase the size of the array. You may assume that no one will ever try to put more than 100 cars or customers in the array.
You will create getters and setters methods that you need. If you create a method that you dont use, you will lose points.
The following need to be verified before it gets stored in the array:
Phone number need to be 10 digits long
Date need to match the format MM/DD/YYYY
Credit card number need to be 16 digits long
You cant rent unless the customer has Insurance. Meaning if you hit enter it should not let you through to the next step of reservation.
Program classes:
Car, customers, staff classes. See details below.
Insurance which will only manage the insurance info includes company and expiration date.
Reservation class manages the car reservations. See details below.
Driver class manages the program. See details below.
UserCredential and verify class- which will manage the staff login to the console.
DataManager- read the customer and car info into arrays and writes info the files again at exit.
Program Files:
We will provide you with 3 text files. Staff.txt, car.txt, and customer.txt
Car class:
General description:
The Car class manages information about a car.
Instance variables:
Make
Model
VIN
Year
Category: such as Economy, Luxury, Full-size car, Full-size Van, and convertible.
Constant for the prices for each category
Economy rate is $30
Luxury rate is $40
Full-size car rate is $35
Full-size Van rate is $50
Convertible rate is $50.
Mileage on the car at the time of rental or return.
Customer an instance of the customers class for the customer who is renting a car.
Reservation flag. Set to true if the car is reserved. And false if its not.
oilChange mileage- stores the mileage for the last time the car had its oil changed.
Methods:
A constructor that takes make, model, VIN, year, mileage, oilChange, reservation flag, category.
Second constructor that takes make, model, VIN, year, mileage, oilChange, reservation flag, category, and customer.
updateMiles()- takes the returns miles for the car and add it to the mileage of the car. Meaning is if the customer rented a car with 30000miles and drove it for 3000 miles then the method will update the 30000 to 33000 miles.
oilChange()- this method will decide if a given car will need to have its oil changed. The way this works is, if car drove 3000 miles since the last time the oil was changed then you need to flag it to have it serviced again. And you need to flag a car whose mileage is close to be services ( lets say 300 miles). Meaning, if a car was services at 3000 miles and someone drove it for more than 3000 then this car need to be flagged to be services. Or if a car is 300 miles shy of being services then you need to flag it to have its oil changed. When listing them, the system will ask the admin if someone changed the oil of the car, if yes then the oilChange will be set to the current car mileage if no then nothing is changed.
Getters and setters method that you need. Only create what you need.
toString()- format the output of the car in a table like. Please see the sample output for it. in this method you need to see if a car has reservation then you need to have the customer information added the string you are returning. But if the car dont have any reservation, then just output the car info. For example
Insurance Information:
Company Expiration
insProvA 33/33/1984
Insurance class:
General description:
The Insurance class manages information about a customer insurance.
Instance variables:
company
expiration date
Methods:
constructor that take the company and the expiration date
getters and setters that you may need.
toString() will print the insurance information in a table like. For example:
Insurance Information:
Company Expiration
insProvA 33/33/1984
Customers class:
General description:
The Customers class manages information about a customer.
Instance variables:
firstName
lastName
phoneNumber
bank name
credit card number
address
insurance- instant of the Insurance class
hasReservation- flag for customer reservation. True if the customer have one, false otherwise.
Cost- for the total cost of the rent including tax
Number of days to rent the car.
Methods:
constructor that takes firstName, lastName, address, phoneNumber, bank, credit card, insurance info, hasResrvation
second constructor that takes firstName, lastName, address, phoneNumber, bank, credit card, insurance info, hasResrvation, cost, and number of days
getters and setter- create what you need.
toString()- format the output in a table like. For example
Customer Information
Full Name Phone Address
John Smith 1231231234 211 W 6th Kent Il
Insurance Inforamtion:
Company Expiration
insProvA, 2/1/2019
Bank Information
Bank credit card Number
Discover 1234567891011121
UserCred class:
General description:
The UserCred class manages information about a staff login.
Instance variables:
username
password
Methods:
constructor that takes the username and password.
Only getters. Dont create setters.
Verify class:
General description:
The verify class verify staff credentials in order to allow him/her to login.
Instance variables:
Array of user credential info. You can specify the size to 10.
Add more instant variables as you see fit.
Methods:
Read staff username and password from a file staff.txt. And stores the info in the array. You need to handle the exception correctly that comes from reading a file. Like NullPointerException and more.
Login() that takes a username and password the staff enters from the keyboard and see if it matches any of the info in the array of user credentials that you read from the file. If it matches any then return true. Otherwise return false.
addUser() that takes a username and password of the new staff from the keyboard and add it to the array and print it out to the text file staff.txt
DataManger class:
Instance variables:
Array of customers.
Array of cars
Methods:
readCar()- method that read car.txt file and save the info in the car array. If the car is reserved, then you need to use the phone number to search for the customer and then save that entry in the car array.
readCustomers()- method that read the customer.txt file and stores the info in customer array. If the customer do have reservation, then you need to read the cost and the number of days in to the customer instance then save it to the customer array.
addCustomer()- takes a customer object and add it to the customer array.
searchCustomer()- takes a phone number for the customer the staff is trying to find. Look through the whole array for customer with that phone number, if it exist you return the customer info.
writeCustomer()- method that write the customer array to customer.txt file in the same format as it initially started.
WriteCar()- method that write the car array to car.txt in the same format as it initially started.
Car.txt format is as follow
VIN Make Model Category Year mileage oilMileage false | OR | VIN Make Model Category Year mileage oilMileage true phoneNumber |
Customer format is as follow
firstName lastName bank credit_card_number insurance_company expiration_date false | OR | firstName lastName address bank credit_card_number phoneNumber insurance_company expiration_date true cost number_of_days |
Reservation class:
Instance variables:
DataManger instance.
Number of days to reserve a car
Start mileage
End mileage
Feel free to create anything else you may need
Methods:
chooseCar()- output a menu for the staff to choose from as follow. It should return the choice.
choose from the following:
category rate/day
1-economy car $30
2-Full-size car $35
3-Luxury car $40
4-Convertible car $50
5-Full-size Van $50
readCustomerInfo()-dont pass anything to this method. This method first will look to see if the customer who is trying to rent a car is in the system or not. You do customer search by phone number. if the customer exists then you print out the customer info and currently dont have a reserved car then you proceed with reservation. But if the customer have reservation already, then the program exit and tells you to return the current car first then allow for a new reservation. If the customer does not exist, then you need to take his info and store it in the customers array.
Reserve()- this method will need the customer info for the reservation as well as the inventory of the cars. Dont pass anything to the method. According to the staff choice of car to rent (see chooseCar()), you need to set the rate and the category. If there is no cars left in that category then list all the cars available to rent and let the user choose which car to rent with the same rate as the first initial category. Meaning is if there is no more Economy cars to rent then let the customer choose from any of the cars you have in the inventory with the same rate as the economy one. You will reserve a car according to the VIN number. part of reservation is to set the customer flag for reservation to true as well as the flag for reservation for the car. In addition, set the start mileage to the current car mileage as well as the number of days to reserve the car. Use the writeCustomer and writeCar methods at the end to update the text files.
carReturn()- this method takes the VIN number. search for the car with that VIN number and set the reservation flag to false as well as the reservation flag for the customer to false. The method will record the mileage that was driven and update the mileage on the car. Use the writeCustomer and writeCar methods at the end to update the text files.
Summary method that prints a summary for the car reservation,
Summary_return that prints a summary for the car return.
Driver class:
First you need to ask the staff to login in, ask for the username and password.
If the staff exist in the system, show a welcome message. Otherwise keep asking for a username and password. The staff can try to login 3 times. more than 3 attempt the program will exist.
If the staff who is logged in is an admin then the menu will be as follow
please choose from the list:
1- reserve a car
2- a car return
3- display inventory
4- search for a car
5- search by customer
6- add new User
7- cars that need oil change
8-logout
For any other user the menu will be like this
1- reserve a car
2- a car return
3- display inventory
4- search for a car
5- search by customer
6- logout
For option 1 you need to call the reserve method and print a summary of the reservation
For option 2 you return a car using a vin number and print a summary for the customer
For option 3: just display the inventory of cars
For option 4: you search for a car using a vin number
For option 5: you search for a customer using a phone number
For option 6: the admin can add a new staff by passing the username and password
For option 7: list the cars that need to have its oil changed.
And 8 just to logout.
The menu will keep appearing until you choose 8, write everything to the files, then show a sign out message and exit the program.
staff.txt:
admin Admin dude dude11
car.txt:
1NDFA03457 NISSAN ALTIMA 2.5S Full-size 2006 39194 34301 false 2ABCD3AXDF HONDA ACCORD LX Luxury car 2005 67124 60245 false 8DEF3AXEEA FORD TAURUS 3.5L economy 2001 53892 50753 true 2177217217 2342ABD143 TOYOTA SIENNA XLE Full-size Van 2011 8000 4000 false
customer.txt:
John Smith 211 W 6th Kent Il Discover 1234567891011121 1231231234 insProvA, 2/1/2019 true 64.5 2
Jane Doe 305 W main st coral il Chase 12345111112345 5755555587 insProvB, 1/31/2020 false
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started