PLEASE PROVIDE THE JAVA CODE FOR THE WHOLE ASSIGNMENT NOT JUST THE FIRST PART La
ID: 3605664 • Letter: P
Question
PLEASE PROVIDE THE JAVA CODE FOR THE WHOLE ASSIGNMENT NOT JUST THE FIRST PART
Lab: Develop a program for an online store which sells dvds and books (items). The store will have a cart which will contain the items the user w an ts to purchase and their price The inventory for books and dvds will be stored in two separate string arrays which will contain the names of the books and the names of the dvds. In addition, two separate arrays of type double will be used to store the price corresponding to each item. You will create the arrays and populate them with data at the beginning of your program. This is how the arrays will look: books Intro to Java Intro to C++ hon Perl | C# booksPrices 45.99 89.34 100.00 25.0049.99 dvds Snow White Cinderella Dumbo Bambi Frozen dvdsPrices 19.99 24.99 17.99 21.9924.99 Moreover, you will implement the cart as two arrays too. The first array is for the names of the items the user wishes to purchase (books or dvds). The second is for the corresponding prices You can assume a maximum cart size of 5 items, i.e., the User cannot have more than 5 items in their cart. After you create and initialize all the arrays and array lists, the program will then display a menu for the user by calling the method displayMenu (). The method will display the following lines when called: **Welcome to the Comets Books and DVDs Store** Choose from the following options 1 - Browse books inventory (price low to high) 2 - Browse DVDs inventory (price low to high) 3 - Add a book to the cart 4 - Add a DVD to the cart 5 - View cart 6 - CheckoutExplanation / Answer
/ 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<Book> 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 < 0)
{
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 < 0)
{
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<Book> list,String title,String author)
{
for(int i=0;i<list.size();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<DVD> 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 < 0)
{
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 < 0)
{
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<DVD> list,String title,String director,int year)
{
for(int i=0;i<list.size();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<Book> 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 < 0)
{
System.out.print(" Invalid ISBN . Enter the ISBN of the book : ");
id = scan.nextInt();
scan.nextLine();
}
for(int i=0;i<list.size();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<DVD> 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 < 0)
{
System.out.print(" Invalid code . Enter the code of the DVD : ");
id = scan.nextInt();
scan.nextLine();
}
for(int i=0;i<list.size();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<Book> bookList, ArrayList<DVD> dvdList)
{
System.out.println(" ****Catalog**** ");
System.out.println(" Books & Audio Books : ");
for(int i=0;i<bookList.size();i++)
System.out.println(bookList.get(i));
System.out.println(" DVDs : ");
for(int i=0;i<dvdList.size();i++)
System.out.println(dvdList.get(i));
}
public static void main(String[] args) {
ArrayList<Book> bookList = new ArrayList<Book>();
ArrayList<DVD> dvdList = new ArrayList<DVD>();
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();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.