Develop car rental application may use to produce a receipt. A receipt will be f
ID: 3790175 • Letter: D
Question
Develop car rental application may use to produce a receipt. A receipt will be formatted as follows:
E Z – R I D E R
Rental Receipt
Customer : John Jones
Driver License : PA 12343
Telephone : 724-555-8345
Credit Card : VISA 12345678012
Vehicle : Mercedes 350E
Tag # : PA 342399
Rent Class : Luxury Sedan
Daily Rate : $ 95.00
Weekly Rate : $ 545.00
Date/Time Out : 01/10/2017 at 10:45
Date/Time In : 01/20/2017 at 11:44
Rental Charge : $ 830.00
Airport Tax : $ 150.00
Sales Tax : $ 49.80
Total : $ 1029.80
For this application create four main classes for customer, rental class, vehicle, and rental agreement. The customer class should have six pieces of information (i.e. instance variables) including customer name (as a String), driver’s license state (as a String), driver’s license number (as an int), telephone number (as a String), credit card type (as a String), and credit card number (as a long). A rental class represents the rental terms for a class of vehicle. For example Compact, Mid-Size, Full Size, Sport etc. are classifications of cars with each time having different rental terms. A rental class should have three pieces of information: a rental class name (as a String), a daily rate (as a double) and a weekly rate (as a double). A vehicle should have four pieces of information: a make/model (as a String), state issuing a tag (as a String), a tag number (as a String) and a rental class (as a rental class). Lastly a rental agreement is the agreement of a customer to rental a given vehicle together with the rental terms, date/time out and date/time in. Thus a rental agreement has 4 pieces of information: the customer, the vehicle, date/time out (as a LocalDateTime) and date/time in.
For your customer class, provide a constructor accepting values for all instance variables. Provide getter methods for all instance variables except account number, but setter methods for only the telephone, credit card type and credit card number variables.
For rental class class, provide a constructor accepting values for all instance variable. Provide getter methods for all instance variables. Likewise for the vehicle class.
For your rental agreement class provide a constructor accepting values for all instance variables except date/time in as it is intended that this field will be given a value only when the customer returns the vehicle. Provide only getter methods for all instance variables. Provide a setter method for only the date/time in variable.
To represent a date/time use Java’s LocalDateTime class. For this class, however, do not use new to create instances. Instead use the of method:
LocalDateTime dateTimeOut = LocalDateTime.of(2017,1,10, 8, 45);
The above example creates a LocalDateTime for 1/10/2017 at 8:45.
In the rental agreement provide getRentalCharge(), getAirportTax(), getSalesTax() and getTotal() methods. The getRentalCharge() is to return the number of days rented times the daily rental rate. The getAirportTax() is to return the number of days rented times $ 15.00. The getTax() is to return the rental change times 6%. The getTotal() is to return the sum of rental charge, airport tax, and tax.
In addition to the special get methods, provide a print receipt method that will print the receipt according to the above format.
A day is a 24 hours period. However, there is a one hour grace in returning a car. That is if a car is returned after 24 hours and 59 minutes, then only one day is used in the computations. To compute the number of days between dateTimeOut and dateTimeIn, use the following code:
int noDays = Duration.between(dateTimeOut,dateTimeIn).plusMinutes(23 * 60);
BONUS 5 points: have the computation of rental charge use weekly rate to the best benefit of the customer. The data in the example is using the weekly rate. That is one week charge plus three days at the daily rate. The weekly rate should be used where it benefits the customer even in cases where it is better than the daily rate. For example if in the example the vehicle was rented 6 days and 1 week rental charges should be used.
In addition, develop another class to test your classes by printing three separate, and different, recepts. This class will have a main method. In the main method, create instances of your classes in order to print the three separate receipts. Thus, you will hard code inside the main the values to be used when instantiating your classes. With the exception of the fixed values given in the computations above (for example .06 for sales tax rate), do not hard code any other data within your classes. For each receipt instance, call the print method to print the receipt. Make sure to call setDateTimeIn appropriately after creating an instance of a rental receipt and before printing.
NOTE: You do not need, and therefore should not, code any routines to input the values from the user or from files. Your test class is sufficient to demonstrate that your classes are working correctly. If you do the bonus, make sure to have data that will test the logic.
Make sure the instance variables are private. Provide javadoc for each class and methods. Abide by good programming practices.
Explanation / Answer
import java.*;
import java.time.LocalDateTime;
import java.time.Duration;
import java.time.Month;
class customer
{
String custName, telNo, ccType, dlState;
int dlNo;
long ccNo;
customer(String name,String phNo, String cardType, String liscState, int dlNum, long cardNo)
{
custName = name;
telNo = phNo;
ccType = cardType;
dlState = liscState;
dlNo = dlNum;
ccNo = cardNo;
}
public String getCustName()
{
return custName;
}
public String getTelNo()
{
return telNo;
}
public String getCCType()
{
return ccType;
}
public String getDlState()
{
return dlState;
}
public int getDlNo()
{
return dlNo;
}
public long getCCNo()
{
return ccNo;
}
public void setTelNo(String teleNo)
{
this.telNo = teleNo;
}
public void setCCType(String CCType)
{
this.ccType = CCType;
}
public void setCCNo(long CCNo)
{
this.ccNo = CCNo;
}
}
class rentDetails
{
String rentClass;
double dailyRate, weeklyRate;
rentDetails(String rentCls, double dailyCharges, double weeklyCharges)
{
rentClass = rentCls;
dailyRate = dailyCharges;
weeklyRate = weeklyCharges;
}
public String getRentClass()
{
return rentClass;
}
public double getDailyRate()
{
return dailyRate;
}
public double getWeeklyRate()
{
return weeklyRate;
}
}
class vehicle
{
String model, tagState, tagNo;
rentDetails RD;
vehicle( String mdl, String tgState, String tgNo, rentDetails rd)
{
model = mdl;
tagState = tgState;
tagNo = tgNo;
RD = rd;
}
public String getModel()
{
return model;
}
public String getTagState()
{
return tagState;
}
public String getTagNo()
{
return tagNo;
}
public rentDetails getRentDetails()
{
return RD;
}
}
class rentAgmt
{
customer cust;
vehicle v;
LocalDateTime dt_time_out;
LocalDateTime dt_time_in;
rentAgmt(customer cst, vehicle V, LocalDateTime dt_Time_Out)
{
cust = cst;
v = V;
dt_time_out = dt_Time_Out;
}
public customer getCust()
{
return cust;
}
public vehicle getVehicle()
{
return v;
}
public LocalDateTime getDt_time_out()
{
return dt_time_out;
}
public LocalDateTime getDt_time_in()
{
return dt_time_in;
}
public void setDt_time_in( LocalDateTime DT_TIME_IN)
{
this.dt_time_in = DT_TIME_IN ;
}
public double getRentalCharge()
{
Duration temp = Duration.between(dt_time_out,dt_time_in).plusMinutes(23 * 60);
long noDays = temp.toDays();
return (v.RD.dailyRate * noDays);
}
public double getAirportTax()
{
Duration temp = Duration.between(dt_time_out,dt_time_in).plusMinutes(23 * 60);
long noDays = temp.toDays();
return (15.00 * noDays);
}
public double getSalesTax()
{
Duration temp = Duration.between(dt_time_out,dt_time_in).plusMinutes(23 * 60);
long noDays = temp.toDays();
return ((v.RD.dailyRate * noDays * 6)/100 );
}
public double getTotal()
{
return (getRentalCharge()+getAirportTax()+getSalesTax());
}
public void printReceipt(int i)
{
System.out.println(" Rental Receipt "+ i);
System.out.println(" Customer :"+ cust.custName);
System.out.println(" Driver Licence :"+cust.dlState);
System.out.println(" Telephone Number :"+cust.telNo);
System.out.println(" Credit Card :"+cust.ccType+" "+cust.ccNo);
System.out.println(" Vehicle :"+v.model);
System.out.println(" Tag # :"+v.tagNo);
System.out.println(" Rent Class :"+v.RD.rentClass );
System.out.println(" Daily Rate :"+v.RD.dailyRate);
System.out.println(" Weekly Rate :"+v.RD.weeklyRate);
System.out.println(" Date/Time out :"+dt_time_out);
System.out.println(" Date/Time in :"+dt_time_in);
System.out.println(" Rental Charge :"+getRentalCharge());
System.out.println(" Airport Tax :"+getAirportTax());
System.out.println(" Sales Tax :"+getSalesTax());
System.out.println(" Total :"+getTotal());
System.out.println(' ');
}
}
public class RentReceipt
{
public static void main(String[] Args)
{
customer cust1 = new customer("Amit","950001316","VISA","AB123",23,123456789);
rentDetails d1 = new rentDetails("A Class",20,80);
vehicle v1 = new vehicle("Merc","MercUS","MercA",d1);
LocalDateTime t1 = LocalDateTime.of(2017, Month.JANUARY, 31, 10, 45);
rentAgmt a1 = new rentAgmt(cust1,v1,t1);
a1.setDt_time_in( LocalDateTime.now());
a1.printReceipt(1);
customer cust2 = new customer("Amrit","951231316","VISA","CD123",24,3828179);
rentDetails d2 = new rentDetails("B Class",30,90);
vehicle v2 = new vehicle("Audi","AudiUS","AudiB",d2);
LocalDateTime t2 = LocalDateTime.of(2017, Month.FEBRUARY, 2, 10, 45);
rentAgmt a2 = new rentAgmt(cust2,v2,t2);
a2.setDt_time_in( LocalDateTime.now());
a2.printReceipt(2);
customer cust3 = new customer("Amrita","951312100","VISA","CD123",25,34174123);
rentDetails d3 = new rentDetails("C Class",40,120);
vehicle v3 = new vehicle("Jaguar","JaguarUS","Jag",d3);
LocalDateTime t3 = LocalDateTime.of(2017, Month.FEBRUARY, 6, 10, 45);
rentAgmt a3 = new rentAgmt(cust3,v3,t3);
a3.setDt_time_in( LocalDateTime.now());
a3.printReceipt(3);
}
}
//notes:
// use javasdk 8 as Localdatetime is supported by Java8
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.