Create an abstract cl that encapsulates a The rental item has four data title, y
ID: 641259 • Letter: C
Question
Create an abstract cl that encapsulates a The rental item has four data title, year of release, UPC and quantity available. Include an abstract method that computes and returns the rental fee (no parameters). Include an extra m in the rental item class to increment and/or decrement the available. Also, throw an illegal argument exception if year of release received is 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(S2.00) A movie disk class that has one attribute that whether the DvD is standard or Blu-Ray. The rental fee is computed with one fee for Blu-Ray and a lower fee for standard Include the usual constructors, accessors, mutators, tostring, copy and equals methods in all of the classes except where not allowed. create one text file that has a collection of at least three video game items, at least three standard DVDs and at least three Blu-Ray DVDs. The data for each item is on a single line, with a common delimiter. Create a Java program that reads the items from the text file (use the tokenizer or split here), creates the appropriate class instance of each item and stores them in an array or ArrayList whose data type is rental item The program should handle the different types of rental items in the file in any order. (i.e. the program determines from the line of the file what type of rental item it is.) Assume the data in the file is free. Catch the file not found exception and other lo exceptions. (No throws in headings.) You choose what to do in the catch blocks. (Display of an error message and termination is acceptable.) The program then interacts with the user so that items may be rented or returned. With each rental or return the number of items available is updated. When item is rented the rental fee is displayed, along with the item rented Before the program terminates, the list of all items in the array or ArrayList is displayed (so well can check the quantities available). will let you decide what information the user enters so the item can be found. (Make your life easy,) If the item the user enters does not exist, just display a "not found" type of message If the user wants to rent an item and it is found, but there are none available, display an "out of stock" type message Run with various rentals and returns and some "not found" and "out of stock" cases Submit printed copies of all commented and formatted code; the text file; and the output from the program. Email all source code and the data file Use the console for VOExplanation / Answer
Program code:
public abstract class RentalItems
{
String title;
int year_released;
String UPC;
int quantity;
RentalItems(String title, int year_released, String UPC, int quantity)
{
this.title=title;
this.year_released=year_released;
this.UPC=UPC;
this.quantity=quantity;
}
abstract public double computeRentalFee();
public int incrementQuantity( )
{
return quantity++;
}
public int decrementQuantity()
{
return quantity--;
}
public String getTitle()
{
return title;
}
public void setTitle(String title)
{
this.title = title;
}
public int getYear_released()
{
return year_released;
}
public void setYear_released(int year_released)
{
this.year_released = year_released;
}
public String getUPC()
{
return UPC;
}
public void setUPC(String upc)
{
UPC = upc;
}
public int getQuantity()
{
return quantity;
}
public void setQuantity(int quantity)
{
this.quantity = quantity;
}
public boolean equals(Object obj)
{
if (this == obj)
{
return true;
}
if (obj == null)
{
return false;
}
if (getClass() != obj.getClass())
{
return false;
}
RentalItems other = (RentalItems) obj;
if (title == null)
{
if (other.title != null)
{
return false;
}
} else if (!title.equals(other.title))
{
return false;
}
return true;
}
public String toString()
{
String s=getTitle()+" "+getYear_released()+" "+getUPC()+" "+getQuantity()+" ";
return s;
}
}
public class VideoGame extends RentalItems
{
String platform;
double rentalFee=2.00;
VideoGame(String title, int year_released, String UPC, int quantity, String platform)
{
super(title, year_released, UPC, quantity);
this.platform=platform;
}
public String getPlatform()
{
return platform;
}
public void setPlatform(String platform)
{
this.platform = platform;
}
public double getRentalFee()
{
return rentalFee;
}
public void setRentalFee(double rentalFee)
{
this.rentalFee = rentalFee;
}
public double computeRentalFee()
{
return rentalFee;
}
public String toString()
{
String s=super.toString()+" ";
return s;
}
}
public class MovieDisk extends RentalItems
{
String DVDtype;
double blu_ray=5.00;
double standard=3.50;
MovieDisk(String title, int year_released, String UPC, int quantity, String DVDtype)
{
super(title, year_released, UPC, quantity);
this.DVDtype=DVDtype;
}
public String getDVDtype()
{
return DVDtype;
}
public void setDVDtype(String dtype)
{
DVDtype = dtype;
}
public double computeRentalFee()
{
double rfee=0;
if(DVDtype.equalsIgnoreCase("standard"))
{
rfee=standard;
}
else if(DVDtype.equalsIgnoreCase("Blu-Ray"))
{
rfee=blu_ray;
}
else
{
System.out.println("Sorry! Could not find the DVD.");
rfee=0;
}
return rfee;
}
public String toString()
{
String s=super.toString()+" ";
return s;
}
}
import java.io.*;
import java.util.*;
public class RentalItemsImplementation
{
static ArrayList<VideoGame> vg=new ArrayList<VideoGame>();
static ArrayList<MovieDisk> md=new ArrayList<MovieDisk>();
public static void main(String args[]) throws Exception
{
Scanner in = new Scanner(System.in);
File file=new File("RentalItemDetails.txt");
Scanner fin=new Scanner(file);
String str[];
if(file.exists())
{
String line="";
while(fin.hasNextLine())
{
line=fin.nextLine();
str=line.split(" ");
if(str[str.length-1].equalsIgnoreCase("xbox")|| str[str.length-1].equalsIgnoreCase("wii")||str[str.length-1].equalsIgnoreCase("ps"))
{
VideoGame vgame=new VideoGame(str[0], Integer.parseInt(str[1]), str[2], Integer.parseInt(str[3]), str[4]);
vg.add(vgame);
}
else if(str[str.length-1].equalsIgnoreCase("Blu-Ray")||str[str.length-1].equalsIgnoreCase("Standard"))
{
MovieDisk mdDVD=new MovieDisk(str[0], Integer.parseInt(str[1]), str[2], Integer.parseInt(str[3]), str[4]);
md.add(mdDVD);
}
}
}
else
{
System.out.println("Sorry! File not found to read.");
}
String name;
String item;
int ch1, ch2;
int count=0;;
int num=0;
double cost=0;
System.out.println("Enter your name: ");
name=in.next();
do{
System.out.println("Welcome to rental item shop.");
System.out.println("1. Rent an item.");
System.out.println("2. Return an item.");
System.out.println("3. Print list of items available");
System.out.println("4. To exit.");
System.out.println("Enter your choice: ");
ch1=in.nextInt();
switch(ch1)
{
case 1:
System.out.println("Type of item would like to rent: ");
System.out.println("1. Video games.");
System.out.println("2. Movies.");
System.out.println("Enter your choice: ");
ch2=in.nextInt();
if(ch2==1)
{
printlist(vg);
System.out.println("Enter the item name: ");
item=in.next();
for(int i=0;i<vg.size();i++)
{
if(item.equalsIgnoreCase(vg.get(i).getTitle()))
{
if(vg.get(i).getQuantity()!=0)
{
cost+=vg.get(i).computeRentalFee();
vg.get(i).decrementQuantity();
num=i;
}
else
{
System.out.println("Sorry! Item is out of stock.");
}
}
}
System.out.println("The item details are: "+ vg.get(num).toString());
System.out.println("The cost of the item is: $"+vg.get(num).computeRentalFee());
count++;
}
else if(ch2==2)
{
printlist(md);
System.out.println("Enter the item name: ");
item=in.next();
for(int i=0;i<md.size();i++)
{
if(item.equalsIgnoreCase(md.get(i).getTitle()))
{
if(md.get(i).getQuantity()!=0)
{
cost+=md.get(i).computeRentalFee();
md.get(i).decrementQuantity();
num=i;
}
else
{
System.out.println("Sorry! Item is out of stock.");
}
}
}
System.out.println("The item details are: "+ md.get(num).toString());
System.out.println("The cost of the item is: $"+md.get(num).computeRentalFee());
count++;
}
break;
case 2:
System.out.println("Type of item would like to return: ");
System.out.println("1. Video games.");
System.out.println("2. Movies.");
System.out.println("Enter your choice: ");
ch2=in.nextInt();
if(ch2==1)
{
printlist(vg);
System.out.println("Enter the item name: ");
item=in.next();
for(int i=0;i<vg.size();i++)
{
if(item.equalsIgnoreCase(vg.get(i).getTitle()))
{
vg.get(i).incrementQuantity();
num=i;
}
}
System.out.println("The item details are: "+ vg.get(num).toString());
count--;
}
else if(ch2==2)
{
printlist(md);
System.out.println("Enter the item name: ");
item=in.next();
for(int i=0;i<vg.size();i++)
{
if(item.equalsIgnoreCase(vg.get(i).getTitle()))
{
vg.get(i).incrementQuantity();
num=i;
}
}
System.out.println("The item details are: "+ vg.get(num).toString());
count--;
}
break;
case 3:
printlist();
break;
case 4:
System.out.println("The name of the customer: "+name);
System.out.println("The total number of items rented are: "+count);
System.out.println("The total amount is: $"+cost);
System.out.println("Thank you for visiting!");
System.exit(0);
break;
default:
System.out.println("Entered wrong choice.");
}
}while(true);
}
public static void printlist()
{
System.out.println("List of Video Games: ");
for(int i=0;i<vg.size();i++)
System.out.println(vg.get(i).toString());
System.out.println("List of Movies: ");
for(int i=0;i<md.size();i++)
System.out.println(md.get(i).toString());
}
public static void printlist(ArrayList v)
{
for(int i=0;i<v.size();i++)
System.out.println(v.get(i).toString());
}
}
Sample Input Text file: RentalItemDetails.txt
PokemonGoldandSilver 1999 123456788990 5 xbox
Battlefield-3 2011 123456789123 4 ps
CallofDuty-Ghosts 2013 201345685793 6 ps
Minecraft 2009 123456789254 10 ps
WiiPlay 2006 302154214587 4 wii
101Dalmatians 2014 352647895426 3 Blu-Ray
St.Vincent 2014 234561257823 4 Blu-Ray
TheTheoryofEverything 2014 324156987254 6 Blu-Ray
BlackSwan 2011 300112244557 2 Blu-Ray
Birdman 2014 112233445566 5 Blu-Ray
Interstellar 2014 332200112102 1 Standard
Gravity 2013 323232323232 6 Standard
TheDarkKnightRises 2012 254316258798 3 Standard
X-Men:DaysofFuturePast 2014 124351685546 2 v
ToyStory-3 2010 335544662211 5 Standard
Sample Output: Console
Enter your name:
Pollocks
Welcome to rental item shop.
1. Rent an item.
2. Return an item.
3. Print list of items available
4. To exit.
Enter your choice:
3
List of Video Games:
PokemonGoldandSilver 1999 123456788990 5
Battlefield-3 2011 123456789123 4
CallofDuty-Ghosts 2013 201345685793 6
Minecraft 2009 123456789254 10
WiiPlay 2006 302154214587 4
List of Movies:
101Dalmatians 2014 352647895426 3
St.Vincent 2014 234561257823 4
TheTheoryofEverything 2014 324156987254 6
BlackSwan 2011 300112244557 2
Birdman 2014 112233445566 5
Interstellar 2014 332200112102 1
Gravity 2013 323232323232 6
TheDarkKnightRises 2012 254316258798 3
ToyStory-3 2010 335544662211 5
Welcome to rental item shop.
1. Rent an item.
2. Return an item.
3. Print list of items available
4. To exit.
Enter your choice:
1
Type of item would like to rent:
1. Video games.
2. Movies.
Enter your choice:
1
PokemonGoldandSilver 1999 123456788990 5
Battlefield-3 2011 123456789123 4
CallofDuty-Ghosts 2013 201345685793 6
Minecraft 2009 123456789254 10
WiiPlay 2006 302154214587 4
Enter the item name:
Minecraft
The item details are: Minecraft 2009 123456789254 9
The cost of the item is: $2.0
Welcome to rental item shop.
1. Rent an item.
2. Return an item.
3. Print list of items available
4. To exit.
Enter your choice:
1
Type of item would like to rent:
1. Video games.
2. Movies.
Enter your choice:
2
101Dalmatians 2014 352647895426 3
St.Vincent 2014 234561257823 4
TheTheoryofEverything 2014 324156987254 6
BlackSwan 2011 300112244557 2
Birdman 2014 112233445566 5
Interstellar 2014 332200112102 1
Gravity 2013 323232323232 6
TheDarkKnightRises 2012 254316258798 3
ToyStory-3 2010 335544662211 5
Enter the item name:
Gravity
The item details are: Gravity 2013 323232323232 5
The cost of the item is: $3.5
Welcome to rental item shop.
1. Rent an item.
2. Return an item.
3. Print list of items available
4. To exit.
Enter your choice:
4
The name of the customer: Pollocks
The total number of items rented are: 2
The total amount is: $5.5
Thank you for visiting!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.