Question: This is my prior code of which needs implementation: // CatalogItem class to store title and price of Book or DVD abstract public class CatalogItem

 This is my prior code of which needs implementation: // CatalogItemclass to store title and price of Book or DVD abstract publicclass CatalogItem { private String title; private double price; public CatalogItem(String title,double

This is my prior code of which needs implementation:

// CatalogItem class to store title and price of Book or DVD

abstract public class CatalogItem {

private String title;

private double price;

public CatalogItem(String title,double price)

{

this.title = title;

this.price = price;

}

public String getTitle()

{

return title;

}

public double getPrice() {

return price;

}

public String toString()

{

return "Title : "+title +" Price :"+price;

}

}

// End of CatalogItem class

// Book class to store details of a Book

public class Book extends CatalogItem {

private String author;

private int isbn;

public Book(String author, int isbn, String title, double price) {

super(title, price);

this.author = author;

this.isbn = isbn;

}

public String getAuthor()

{

return author;

}

public int getIsbn()

{

return isbn;

}

public String toString()

{

return super.toString() + " Author : "+author +" ISBN : "+isbn;

}

}

// End of Book class

// AudioBook class to store details of an Audio Book

public class AudioBook extends Book {

double runningTime;

public AudioBook(String author, int isbn, String title, double price, double runningTime) {

super(author, isbn, title, price);

this.runningTime = runningTime;

}

public double getPrice() {

return (0.9*getPrice());

}

public double getRunningTime()

{

return runningTime;

}

public String toString()

{

return super.toString() + " Running time : "+runningTime;

}

}

// End of AudioBook class

// DVD class to store details of a DVD

public class DVD extends CatalogItem{

String director;

int year;

int dvdCode;

public DVD(String title, double price, String director,int year,int dvdCode) {

super(title, price);

this.director = director;

this.year = year;

this.dvdCode = dvdCode;

}

public String getDirector()

{

return director;

}

public int getYear()

{

return year;

}

public int getdvdCode()

{

return dvdCode;

}

public String toString()

{

return super.toString() + " Director : "+ director+" Year : "+year+" Dvd Code: "+dvdCode;

}

}

// End of DVD class

// Java program to implement a Catalog for a Book and DVD store

import java.util.ArrayList;

import java.util.Scanner;

public class CommetsStore {

public static void displayMenu() {

System.out.println("** Welcome to the Commets Book and DVDs Store (Catalog Section) **");

System.out.println(" Choose from the following options: ");

System.out.println(" 1- Add Book");

System.out.println(" 2- Add AudioBook");

System.out.println(" 3- Add DVD");

System.out.println(" 4- Remove Book");

System.out.println(" 5- Remove DVD");

System.out.println(" 6- Display Catalog");

System.out.println(" 9- Exit");

}

public static int addBook(ArrayList list,int id, boolean isAudioBook)

{

String title,author;

double price,runningTime = 0;

Scanner scan = new Scanner(System.in);

System.out.print(" Enter title of the book : ");

title = scan.nextLine();

System.out.print(" Enter author of the book : ");

author = scan.nextLine();

System.out.print(" Enter price of the book : $");

price = scan.nextDouble();

scan.nextLine();

while(price

{

System.out.print(" Invalid price. Enter the price of the book : $");

price = scan.nextDouble();

scan.nextLine();

}

//scan.nextLine();

if(isAudioBook)

{

System.out.print(" Enter the running time of the book : ");

runningTime = scan.nextDouble();

scan.nextLine();

while(runningTime

{

System.out.print(" Invalid running time . Enter the running time of the book : ");

runningTime = scan.nextDouble();

scan.nextLine();

}

}

int bookId = isBookPresent(list,title,author);

if(bookId != -1)

{

System.out.println(" Book already exists with ISBN : "+bookId);

}else {

if(isAudioBook)

list.add(new AudioBook(author,id,title,price,runningTime));

else

list.add(new Book(author,id,title,price));

System.out.println(" Your book with has been added with ISBN :"+id);

id++;

}

//scan.close();

return id;

}

public static int isBookPresent(ArrayList list,String title,String author)

{

for(int i=0;i

{

if(list.get(i).getAuthor().equalsIgnoreCase(author) && list.get(i).getTitle().equalsIgnoreCase(title))

return list.get(i).getIsbn();

}

return -1;

}

public static int addDVD(ArrayList list,int id)

{

String title,director;

double price;

int year;

Scanner scan = new Scanner(System.in);

System.out.print(" Enter title of the DVD : ");

title = scan.nextLine();

System.out.print(" Enter director of the DVD : ");

director = scan.nextLine();

System.out.print(" Enter price of the DVD : $");

price = scan.nextDouble();

scan.nextLine();

while(price

{

System.out.print(" Invalid price. Enter the price of the DVD : $");

price = scan.nextDouble();

scan.nextLine();

}

System.out.print(" Enter the year of the DVD : ");

year = scan.nextInt();

scan.nextLine();

while(year

{

System.out.print(" Invalid year. Enter the year of the DVD : ");

price = scan.nextInt();

scan.nextLine();

}

int dvdId = isDVDPresent(list, title, director ,year);

if(dvdId != -1)

{

System.out.println(" Dvd already exists with dvdCode : "+dvdId);

}else {

list.add(new DVD(title,price,director,year,id));

System.out.println(" Your DVD with has been added with code :"+id);

id++;

}

//scan.close();

return id;

}

public static int isDVDPresent(ArrayList list,String title,String director,int year)

{

for(int i=0;i

if(list.get(i).getTitle().equalsIgnoreCase(title) && list.get(i).getDirector().equalsIgnoreCase(director) && list.get(i).getYear() == year)

return list.get(i).getdvdCode();

return -1;

}

public static void removeBook(ArrayList list)

{

int id;

boolean bookFound = false;

Scanner scan = new Scanner(System.in);

System.out.print(" Enter the ISBN of the book : ");

id = scan.nextInt();

scan.nextLine();

while(id

{

System.out.print(" Invalid ISBN . Enter the ISBN of the book : ");

id = scan.nextInt();

scan.nextLine();

}

for(int i=0;i

{

if(list.get(i).getIsbn() == id) {

list.remove(i);

System.out.println(" Book with ISBN "+id+" removed");

bookFound = true;

break;

}

}

if(!bookFound)

System.out.println(" Book with ISBN : "+id+" doesn't exist ");

//scan.close();

}

public static void removeDVD(ArrayList list)

{

int id;

boolean dvdFound = false;

Scanner scan = new Scanner(System.in);

System.out.print(" Enter the code of the DVD : ");

id = scan.nextInt();

scan.nextLine();

while(id

{

System.out.print(" Invalid code . Enter the code of the DVD : ");

id = scan.nextInt();

scan.nextLine();

}

for(int i=0;i

{

if(list.get(i).getdvdCode() == id) {

list.remove(i);

System.out.println(" Book with Code "+id+" removed");

dvdFound = true;

break;

}

}

if(!dvdFound)

System.out.println(" DVD with code : "+id+" doesn't exist ");

//scan.close();

}

public static void displayCatalog(ArrayList bookList, ArrayList dvdList)

{

System.out.println(" ****Catalog**** ");

System.out.println(" Books & Audio Books : ");

for(int i=0;i

System.out.println(bookList.get(i));

System.out.println(" DVDs : ");

for(int i=0;i

System.out.println(dvdList.get(i));

}

public static void main(String[] args) {

ArrayList bookList = new ArrayList();

ArrayList dvdList = new ArrayList();

int bookId = 1;

int dvdCode = 1;

int response;

Scanner scan = new Scanner(System.in);

do {

displayMenu();

System.out.print("Enter your choice : ");

response = scan.nextInt();

scan.nextLine();

switch(response)

{

case 1: bookId = addBook(bookList,bookId,false);

break;

case 2: bookId = addBook(bookList,bookId,true);

break;

case 3: dvdCode = addDVD(dvdList,dvdCode);

break;

case 4: removeBook(bookList);

break;

case 5 : removeDVD(dvdList);

break;

case 6: displayCatalog(bookList,dvdList);

break;

case 9:

break;

default : System.out.println(" Invalid option ");

break;

}

}while(response != 9);

scan.close();

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!