Develop car rental application may use to produce a receipt. A receipt will be f
ID: 3787785 • Letter: D
Question
Develop car rental application may use to produce a receipt. A receipt will be formatted as follows: 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, dateltime out (as a LocalDate Time) and datetime in. your customer class, provide a constructor accepting values for all instance variables. Provide getter methods for all instance variables, but methods for only the telephone, credit card type and credit card number variables.Explanation / Answer
/** * Customer class */ public class Customer { private String name; private String licenseState; private int licenseNumber; private String telephoneNumber; private String creditCardType; private long creditCardNumber; public String getName() { return name; } public String getLicenseState() { return licenseState; } public int getLicenseNumber() { return licenseNumber; } public String getTelephoneNumber() { return telephoneNumber; } public String getCreditCardType() { return creditCardType; } public long getCreditCardNumber() { return creditCardNumber; } public Customer(String name, String licenseState, int licenseNumber, String telephoneNumber, String creditCardType, long creditCardNumber) { this.name = name; this.licenseState = licenseState; this.licenseNumber = licenseNumber; this.telephoneNumber = telephoneNumber; this.creditCardType = creditCardType; this.creditCardNumber = creditCardNumber; } public void setTelephoneNumber(String telephoneNumber) { this.telephoneNumber = telephoneNumber; } public void setCreditCardType(String creditCardType) { this.creditCardType = creditCardType; } public void setCreditCardNumber(long creditCardNumber) { this.creditCardNumber = creditCardNumber; } } /** * RentalClass class */ public class RentalClass { private String rentalClassName; private double dailyRate; private double weeklyRate; public RentalClass(String rentalClassName, double dailyRate, double weeklyRate) { this.rentalClassName = rentalClassName; this.dailyRate = dailyRate; this.weeklyRate = weeklyRate; } public String getRentalClassName() { return rentalClassName; } public void setRentalClassName(String rentalClassName) { this.rentalClassName = rentalClassName; } public double getDailyRate() { return dailyRate; } public void setDailyRate(double dailyRate) { this.dailyRate = dailyRate; } public double getWeeklyRate() { return weeklyRate; } public void setWeeklyRate(double weeklyRate) { this.weeklyRate = weeklyRate; } } /** * Vehicle class */ public class Vehicle { private String model; private String stateTag; private String tagNumber; private RentalClass rentalClass; public Vehicle(String model, String stateTag, String tagNumber, RentalClass rentalClass) { this.model = model; this.stateTag = stateTag; this.tagNumber = tagNumber; this.rentalClass = rentalClass; } public String getModel() { return model; } public void setModel(String model) { this.model = model; } public String getStateTag() { return stateTag; } public void setStateTag(String stateTag) { this.stateTag = stateTag; } public String getTagNumber() { return tagNumber; } public void setTagNumber(String tagNumber) { this.tagNumber = tagNumber; } public RentalClass getRentalClass() { return rentalClass; } public void setRentalClass(RentalClass rentalClass) { this.rentalClass = rentalClass; } } import java.time.Duration; import java.time.LocalDateTime; /** * RentalAgreement class */ public class RentalAgreement { private Customer customer; private Vehicle vehicle; private LocalDateTime dateTimeOut; private LocalDateTime dateTimeIn; public RentalAgreement(Customer customer, Vehicle vehicle, LocalDateTime localDateTimeOut) { this.customer = customer; this.vehicle = vehicle; dateTimeOut = localDateTimeOut; } public Customer getCustomer() { return customer; } public Vehicle getVehicle() { return vehicle; } public LocalDateTime getDateTimeOut() { return dateTimeOut; } public LocalDateTime getDateTimeIn() { return dateTimeIn; } public void setDateTimeIn(LocalDateTime dateTimeIn) { this.dateTimeIn = dateTimeIn; } /** * To calculate number of days rented times the daily rental rate * * @return charge in double */ public double getRentalCharge() { long noDays = Duration.between(dateTimeOut, dateTimeIn).plusMinutes(23 * 60).toDays(); double dailyCharge = noDays * getVehicle().getRentalClass().getDailyRate(); long weeks = noDays / 7; long days = noDays % 7; double weeklyCharge = weeks * getVehicle().getRentalClass().getDailyRate() + days * getVehicle().getRentalClass().getDailyRate(); return Math.min(dailyCharge, weeklyCharge); } /** * To calculate number of days rented times $15.00 * * @return airportTax */ public double getAirportTax() { long noDays = Duration.between(dateTimeOut, dateTimeIn).plusMinutes(23 * 60).toDays(); return noDays * 15.00; } /** * To calculate rental charge times 6%; * * @return tax */ public double getTax() { return getRentalCharge() * 0.06; } /** * To calculate total charge having rental charge, airport tax and tax; * * @return total charnge */ public double getTotal() { return getRentalCharge() + getAirportTax() + getTax(); } /** * To print receipt for customer */ public void printReceipt() { System.out.println(" E Z - R I D E R"); System.out.println(" Rental Receipt"); System.out.println(String.format("Customer : %s", getCustomer().getName())); System.out.println(String.format("Driver License : %s %d", getCustomer().getLicenseState(), getCustomer().getLicenseNumber())); System.out.println(String.format("Telephone : %s", getCustomer().getTelephoneNumber())); System.out.println(String.format("Credit Card : %s %d", getCustomer().getCreditCardType(), getCustomer().getCreditCardNumber())); System.out.println(); System.out.println(); System.out.println(String.format("Vehicle : %s", getVehicle().getModel())); System.out.println(String.format("Tag # : %s %s", getVehicle().getStateTag(), getVehicle().getTagNumber())); System.out.println(String.format("Rent Class : %s", getVehicle().getRentalClass())); System.out.println(String.format("Daily Rate : $%8.2f", getVehicle().getRentalClass().getDailyRate())); System.out.println(String.format("Weekly Rate : $%8.2f", getVehicle().getRentalClass().getWeeklyRate())); System.out.println(); System.out.println(); LocalDateTime outTime = getDateTimeOut(); LocalDateTime inTime = getDateTimeIn(); System.out.println(String.format("Date/Time Out : %2d/%2d/%4d at %2d:%2d", outTime.getMonthValue(), outTime.getDayOfMonth(),outTime.getYear(),outTime.getHour(),outTime.getMinute())); System.out.println(String.format("Date/Time In : %2d/%2d/%4d at %2d:%2d", inTime.getMonthValue(), inTime.getDayOfMonth(),inTime.getYear(),inTime.getHour(),inTime.getMinute())); System.out.println(String.format("Rental Charge : $%8.2f", getRentalCharge())); System.out.println(String.format("Airport Tax : $%8.2f", getAirportTax())); System.out.println(String.format("Sales Tax Rate : $%8.2f", getTax())); System.out.println(String.format("Total : $%8.2f", getTotal())); } } import java.time.LocalDateTime; /** * Test Class */ public class TestClass { public static void main(String args[]) throws Exception { Customer customer = new Customer("John Jones", "PA", 12343, "765-444-3245", "VISA", 1234567890); RentalClass rentalClass = new RentalClass("Luxury Sedan", 95.00, 545.00); Vehicle vehicle = new Vehicle("Merchedes 350E","PA","342399",rentalClass); LocalDateTime localDateTimeout = LocalDateTime.of(2017, 1, 10, 8 ,45); RentalAgreement rentalAgreement = new RentalAgreement(customer ,vehicle,localDateTimeout); LocalDateTime localDateTimein = LocalDateTime.of(2017, 1, 20, 11 ,44); rentalAgreement.setDateTimeIn(localDateTimein); rentalAgreement.printReceipt(); customer = new Customer("Alex Alon", "NY", 12443, "765-434-3245", "MASTER", 1234567890); rentalClass = new RentalClass("Luxury HatchBack", 85.00, 450.00); vehicle = new Vehicle("Wolkswagen E5","NY","341399",rentalClass); localDateTimeout = LocalDateTime.of(2017, 1, 10, 8 ,45); rentalAgreement = new RentalAgreement(customer ,vehicle,localDateTimeout); localDateTimein = LocalDateTime.of(2017, 1, 16, 10 ,44); rentalAgreement.setDateTimeIn(localDateTimein); rentalAgreement.printReceipt(); customer = new Customer("John Jones", "LA", 12343, "765-444-3245", "AMERICAN", 123457820); rentalClass = new RentalClass("Luxury SUV", 105.00, 600.00); vehicle = new Vehicle("Audi Q5","LA","345399",rentalClass); localDateTimeout = LocalDateTime.of(2017, 1, 10, 8 ,45); rentalAgreement = new RentalAgreement(customer ,vehicle,localDateTimeout); localDateTimein = LocalDateTime.of(2017, 2, 9, 11 ,41); rentalAgreement.setDateTimeIn(localDateTimein); rentalAgreement.printReceipt(); } }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.