Write the following java application. Define a class DVD which has fields: Strin
ID: 3675406 • Letter: W
Question
Write the following java application.
Define a class DVD which has fields: String -Title and Genre, Int Year and Number_in_Store, Float price. Make the class Serializable. Use a binary file for saving. Write an application that could be used in a store that sells movies. Use an array to store the Videos in. Allow a user to 1. Enter new videos into the array, 2. Sell a Video to a customer by looking the video up by title and displaying the price, if the customer decides to buy deducts 1 from the number on hand, 3. Add copies of an existing video to the store, 5. Change the price of a video, 6. List all videos in the store and number in Store, 7. Quit. When the user quits the videos are written to a binary file. When the program starts up it prompts the user for a file name and reads the videos from the file. If no file exist it starts with no inventory.Explanation / Answer
import java.util.*;
class DVD
{
public static String[] Title=new String[100];
public static String[] Genre=new String[100];
public static int[] Year=new int[100];
public static int[] Number_in_Store=new int
[100];
public static double[] price=new double[100];
public static int i=0;
public static int menu()
{
int c;
Scanner scan = new Scanner
(System.in);
System.out.println("1. Enter new
Video");
System.out.println("2. Sell a Video");
System.out.println("3. Add copies");
System.out.println("4. Change price of
Video");
System.out.println("5. List all
Videos");
System.out.println("6. Quit");
System.out.println("Enter your
choice");
c=scan.nextInt();
return c;
}
public static void add()
{
i++;
Scanner scan = new Scanner
(System.in);
System.out.println("Enter Title");
Title[i]=scan.nextLine();
System.out.println("Enter Genre");
Genre[i]=scan.nextLine();
System.out.println("Enter Year");
Year[i]=scan.nextInt();
System.out.println("Enter No of
copies");
Number_in_Store[i]=scan.nextInt();
System.out.println("Enter Price");
price[i]=scan.nextDouble();
}
public static void sell()
{
Scanner scan = new Scanner
(System.in);
System.out.println("Enter Title of
Video");
String s=scan.nextLine();
for(int j=0;j<Title.length;j++)
{
if(s.equals(Title[j]))
Number_in_Store[j]-=1;
}
}
public static void copies()
{
Scanner scan = new Scanner
(System.in);
System.out.println("Enter Title of
Video");
String s=scan.nextLine();
for(int j=0;j<Title.length;j++)
{
if(s.equals(Title[i]))
Number_in_Store[i]+=1;
}
}
public static void change()
{
Scanner scan = new Scanner
(System.in);
System.out.println("Enter Title of
Video");
String s=scan.nextLine();
for(int j=0;j<Title.length;j++)
{
if(s.equals(Title[j]))
{
System.out.println("Enter new price");
double p=scan.nextInt();
price[j]=p;
}
}
}
public static void print()
{
int j;
for(j=0;j<=i;j++)
System.out.println(Title[j]
+" "+Number_in_Store[j]);
}
public static void main(String args[])
{
while(true)
{
int cc=menu();
switch(cc)
{
case 1:
add();
break;
case 2:
sell();
break;
case 3:
copies();
break;
case 4:
change();
break;
case 5:
print();
break;
case 6:
return;
}
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.