Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

COSC 210 COSC 210-object oriented and GUI Programming Assignment 2 Problem State

ID: 3789804 • Letter: C

Question

COSC 210 COSC 210-object oriented and GUI Programming Assignment 2 Problem Statement Develop car rental application may use to produce a receipt. A receipt will be format 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 narne (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 makemodel (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, vehicle, dateltime 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, but setter methods for only the telephone, credit card type and credit card number variables.

Explanation / Answer

Customer.java

package com.chegg.application2;

public class Customer {
   private String customerName;
   private String dlState;
   private int licenseNumber;
   private String telephoneNumber;
   private String ccardType;
   private long ccardNumber;

   public Customer(String customerName, String dlState, int licenseNumber, String telephoneNumber, String ccardType,
           long ccardNumber) {
       super();
       this.customerName = customerName;
       this.dlState = dlState;
       this.licenseNumber = licenseNumber;
       this.telephoneNumber = telephoneNumber;
       this.ccardType = ccardType;
       this.ccardNumber = ccardNumber;
   }

   public String getCustomerName() {
       return customerName;
   }

   public String getDlState() {
       return dlState;
   }

   public int getLicenseNumber() {
       return licenseNumber;
   }

   public String getTelephoneNumber() {
       return telephoneNumber;
   }

   public String getCcardType() {
       return ccardType;
   }

   public long getCcardNumber() {
       return ccardNumber;
   }

   public void setTelephoneNumber(String telephoneNumber) {
       this.telephoneNumber = telephoneNumber;
   }

   public void setCcardType(String ccardType) {
       this.ccardType = ccardType;
   }

   public void setCcardNumber(long ccardNumber) {
       this.ccardNumber = ccardNumber;
   }

}

Reantal.java

package com.chegg.application2;

public class Rental {
   private String rcName; // rental class name
   private double dailyRate;
   private double weeklyRate;

   public Rental(String rcName, double dailyRate, double weeklyRate) {
       super();
       this.rcName = rcName;
       this.dailyRate = dailyRate;
       this.weeklyRate = weeklyRate;
   }

   public String getRcName() {
       return rcName;
   }

   public double getDailyRate() {
       return dailyRate;
   }

   public double getWeeklyRate() {
       return weeklyRate;
   }

}

Vehicle.java

package com.chegg.application2;

public class Vehicle {
   private String model;
   private String siTag; // state issuing tag
   private String tagNumber;
   private Rental rentalClass;
   public Vehicle(String model, String siTag, String tagNumber, Rental rentalClass) {
       super();
       this.model = model;
       this.siTag = siTag;
       this.tagNumber = tagNumber;
       this.rentalClass = rentalClass;
   }
   public String getModel() {
       return model;
   }
   public String getSiTag() {
       return siTag;
   }
   public String getTagNumber() {
       return tagNumber;
   }
   public Rental getRentalClass() {
       return rentalClass;
   }
  
  

}

RentalAgreement.java

package com.chegg.application2;


import java.time.Duration;
import java.time.LocalDateTime;


public class RentalAgreement {
   private Customer customer;
   private Vehicle vehicle;
   private LocalDateTime dateTimeOut;
   private LocalDateTime dateTimeIn;
   public RentalAgreement(Customer customer, Vehicle vehicle, LocalDateTime dateTimeOut) {
       super();
       this.customer = customer;
       this.vehicle = vehicle;
       this.dateTimeOut = dateTimeOut;
   }
   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;
   }
  
   public double getRentalCharge(){
       LocalDateTime dateTimeOut = LocalDateTime.of(2017,1,10,10,45);
       LocalDateTime dateTimeIn = LocalDateTime.of(2017,1,20,11,44);
       int numberOfdays = (int) Duration.between(dateTimeOut, dateTimeIn).plusMinutes(23*60).toDays();
       int remaingDate = numberOfdays - 7;
       Rental rental = new Rental("Luxury Sedan", 95.00, 545.00);
       double dailyRate = (rental.getWeeklyRate())+remaingDate*rental.getDailyRate();
       return dailyRate;
      
   }
  
   public double getAirportTax(){
       LocalDateTime dateTimeOut = LocalDateTime.of(2017,1,10,10,45);
       LocalDateTime dateTimeIn = LocalDateTime.of(2017,1,20,11,44);
       int numberOfdays = (int) Duration.between(dateTimeOut, dateTimeIn).plusMinutes(23*60).toDays();
       return (numberOfdays*15.0);
   }
   public double getTax(){
       return (getRentalCharge()*6)/100;
   }
  
   public double getTotal(){
       return getRentalCharge()+getAirportTax()+getTax();
   }

}

Test Class : Test.java

package com.chegg.application2;

import java.time.LocalDateTime;

public class Test {

   public static void main(String[] args) {
       Customer customer = new Customer("John Jones", "PA", 12343, "7245558349", "VISA", 1234567890);
       Vehicle vehicle = new Vehicle("Mersedes 350E", "PA", "342399", new Rental("Luxury Sedan", 95.00, 545.00));
       LocalDateTime dateTimeOut = LocalDateTime.of(2017,1,10,10,45);
       RentalAgreement rentalAgreement = new RentalAgreement(customer, vehicle, dateTimeOut);
       System.out.println("***********EZ - RIDERS*************");
       System.out.println("***********Rental Reciept**********");
       LocalDateTime dateTimeIn = LocalDateTime.of(2017,1,20,11,44);
       System.out.println("Customer Name :"+" "+customer.getCustomerName());
       System.out.println("Driving License :"+" "+customer.getDlState()+" "+customer.getLicenseNumber());
       System.out.println("Telephone :"+" "+customer.getTelephoneNumber());
       System.out.println("Credit Card :"+" "+customer.getCcardType()+" "+customer.getCcardNumber());
       System.out.println();
       System.out.println("Vehicle :"+" "+vehicle.getModel());
       System.out.println("Tag # :"+" "+vehicle.getSiTag()+" "+vehicle.getTagNumber());
       System.out.println("Rent class :"+" "+vehicle.getRentalClass().getRcName());
       System.out.println("Daily Rate :"+" "+"$"+vehicle.getRentalClass().getDailyRate());
       System.out.println("Weekly Rate :"+" "+"$"+vehicle.getRentalClass().getWeeklyRate());
       System.out.println();
       System.out.println("Date/Time out :"+" "+dateTimeOut);
       System.out.println("Date/Time in :"+" "+dateTimeIn);
       System.out.println("Rental Charge :"+" "+"$"+rentalAgreement.getRentalCharge());
       System.out.println("Airport Tax :"+" "+"$"+rentalAgreement.getAirportTax());
       System.out.println("Sales Tax :"+" "+"$"+rentalAgreement.getTax());
       System.out.println("Tatal :"+" "+"$"+rentalAgreement.getTotal());
      
   }

}

Output:

***********EZ - RIDERS*************
***********Rental Reciept**********
Customer Name :       John Jones
Driving License : PA 12343
Telephone : 7245558349
Credit Card : VISA 1234567890

Vehicle : Mersedes 350E
Tag # : PA 342399
Rent class : Luxury Sedan
Daily Rate : $95.0
Weekly Rate : $545.0

Date/Time out : 2017-01-10T10:45
Date/Time in : 2017-01-20T11:44
Rental Charge : $830.0
Airport Tax : $150.0
Sales Tax : $49.8
Tatal : $1029.8