IN JAVA LANGUAGE PLEASE: Create three classes: Customer, Video, and Invoice that
ID: 3670775 • Letter: I
Question
IN JAVA LANGUAGE PLEASE:
Create three classes: Customer, Video, and Invoice that might be used in a video rental store application.
The CUSTOMER class represents a customer. It should have 6 attributes: customer name( String), customer street address ( String), city( String), state( String), zip code ( String) and telephone number (String). For the customer class provide a parametrized constructor that receives the customer name, street address, city, state, zip code, and telephone number as parameters. Provide getter methods as needed for this assignment.
The VIDEO class represents a video being rented. It should have 4 attributes: video name( String),year( integer), copy number ( integer), and daily rental rate ( double). For the VIDEO class, provide a parameterized constructor that receives the video name, year, copy number and daily rate. Provide getter methods as needed for this assignment.
An INVOICE object represents a rental of a video to a given customer. It includes 4 attributes: the customer renting the video, the video being rented, date rented ( String), and the number of days rented( integer). For the INVOICE class, provide a parameterized constructor that receives a customer, video, date rented, and days rented as parameters. Provide getter methods for all instance variables. Provide three methods:
SUBTOTAL that returns the calculated value that is the number of days rented times the daily rate of the video.
TAX which return the tax calculated by multiplying the subtotal plus tax.
TOTAL which returns the subtotal plus tax .
Lastly, provide a printInvoice method that prints a complete invoice in a well formatted report using the 3 methods list above.
DEVELOP A TEST APPLICATION NAMED PROG4 THAT TESTS YOUR THREE CLASSES. THE TEST APPLICATION MUST PRINT AT LEAST THREE DIFFERENT INVOICES FOR ATLEAST TWO DIFFERENT CUTSOMERS AND TWO DIFFERENT VIDEOS.
Explanation / Answer
Customer.java
public class Customer {
private String customerName;
private String customerStreetAddress;
private String city;
private String state;
private String zipCode;
private String telephoneNumber;
public Customer(String name,String address,String custCity,String custState,String zip,String tel)
{
customerName=name;
customerStreetAddress=address;
city=custCity;
state=custState;
zipCode=zip;
telephoneNumber=tel;
}
public String getCustomerName() {
return customerName;
}
public String getCustomerStreetAddress() {
return customerStreetAddress;
}
public String getCity() {
return city;
}
public String getState() {
return state;
}
public String getZipCode() {
return zipCode;
}
public String getTelephoneNumber() {
return telephoneNumber;
}
}
Video.java
public class Video {
private String videoName;
private int year;
private int copyNumber;
private double dailyRentalRate;
public Video(String name,int vYear,int vCopyNum,double rental)
{
videoName=name;
year=vYear;
copyNumber=vCopyNum;
dailyRentalRate=rental;
}
public String getVideoName() {
return videoName;
}
public int getYear() {
return year;
}
public int getCopyNumber() {
return copyNumber;
}
public double getDailyRentalRate() {
return dailyRentalRate;
}
}
Invoice.java
public class Invoice {
private static final double taxRate=5.00;
private Video rentedVideo;
private Customer customer;
private String dateRented;
private int daysRented;
public Invoice(Customer cust,Video vid,String date,int days)
{
customer=cust;
rentedVideo=vid;
dateRented=date;
daysRented=days;
}
public Video getRentedVideo() {
return rentedVideo;
}
public Customer getCustomer() {
return customer;
}
public String getDateRented() {
return dateRented;
}
public int getDaysRented() {
return daysRented;
}
public double subtotal()
{
double subTotal=daysRented*rentedVideo.getDailyRentalRate();
return subTotal;
}
public double tax()
{
double taxCalc=this.subtotal()*taxRate/100;
return taxCalc;
}
public double total()
{
double totalRent=subtotal()+tax();
return totalRent;
}
public void printInvoice()
{
System.out.println("--------INVOICE---------");
System.out.println("Date rented on :"+dateRented);
System.out.println("Video rented :"+rentedVideo.getVideoName());
System.out.println("Daily rental charge $"+rentedVideo.getDailyRentalRate());
System.out.println("Rented for :"+daysRented+" days");
System.out.println("Subtotal $"+subtotal());
System.out.println("Tax $"+tax());
System.out.println("Total $"+total());
System.out.println();
}
}
PROG4.java
public class PROG4 {
public static void main(String[] args) {
Customer c1=new Customer("Jhon","252/122 Stefan Street","Albany","Newyork","12201","(817) 569-8900");
Customer c2=new Customer("Kevin","120 2nd St","Albany","Newyork","12202","(817) 539-1100");
Video v1=new Video("Die Hard-1",2001,4,4.50);
Video v2=new Video("Blood Diamond",2006,1,5.25);
Invoice i1=new Invoice(c1,v1,"2/21/2016",2);
Invoice i2=new Invoice(c2,v2,"2/22/2016",3);
Invoice i3=new Invoice(c1,v2,"2/20/2016",1);
i1.printInvoice();
i2.printInvoice();
i3.printInvoice();
}
}