In java Create an abstract class that encapsulates a rental item. The rental ite
ID: 641182 • Letter: I
Question
In java Create an abstract class that encapsulates a rental item. The rental item has four data members: title ,year of release ,UPC , and quanity available. Include an abstract method that computes and returns the rental fee(no parameters). Include an extra method in the rental item class to increment/or decrement the quanity available. Also, thorw an illegal argument exception if the year of release in before 1995.
Create two subclasses for the rental item class:
A video game class that has one attribute , platform(xbox,ps,wii). The rental fee is the same for each platform($2.00)
A movie disk class that has one attribute that indicates whether the dvd is standard or bluray. The rental fee is computed with one fee for blu ray and a lower for standard.
Stuck and need help!
Explanation / Answer
Driver.java
abstract class RentalItem{
private String title;
private int YearOfRelease;
private int UPC,Quantity;
public abstract int getRentalFee();
public RentalItem(String title,int YearOfRelease,int UPC, int Quantity){
this.title = title;
this.YearOfRelease = YearOfRelease;
this.UPC = UPC;
this.Quantity = Quantity;
}
public int ChangeQuantityBy(int Q){
if(YearOfRelease >= 1995) {
this.Quantity = this.Quantity + (Q);
return this.Quantity;
}
else
throw new IllegalArgumentException();
};
}
enum Platform{
XBOX,PS,WII
}
enum Type{
BLURAY,STANDARD
}
class VideoGame extends RentalItem{
private Platform currPlatform;
public VideoGame(String title,int Year,int UPC,int Quantity,Platform p){
super(title,Year,UPC,Quantity);
this.currPlatform = p;
}
public void setCurrPlatform(Platform p){
this.currPlatform = p;
}
public int getRentalFee(){
return (2);
}
}
class MovieDisk extends RentalItem{
private Type currType;
public MovieDisk(String title,int Year,int UPC,int Quantity, Type t){
super(title,Year,UPC,Quantity);
this.currType = t;
}
public void setCurrType(Type t){
this.currType = t;
}
public int getRentalFee(){
if(currType == Type.BLURAY){
return(10); //Higher value for blueray
}
else if(currType == Type.STANDARD){
return(5); //Lower value for standard
}
return -1;
}
}
/******This is just for testing the above implementation******/
public class Driver {
public static void main(String... args){
RentalItem myConsole1 = new VideoGame("buddy1",1992,12312,4,Platform.PS);
VideoGame myConsole2 = new VideoGame("buddy2",1995,12312,4,Platform.WII);
MovieDisk myPlay1 = new MovieDisk("buddy3",1996,12312,4,Type.BLURAY);
RentalItem myPlay2 = new MovieDisk("buddy3",1992,12312,4,Type.STANDARD);
System.out.println(myPlay2.getRentalFee());
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.