Question

In: Computer Science

this won't compile package com.test; public class CatalogItem { private String title; private double price; public...

this won't compile

package com.test;

public class CatalogItem {

private String title;

private double price;

public CatalogItem(String title, double price) {

super();

this.title = title;

this.price = price;

}

public String getTitle() {

return title;

}

public double getPrice() {

return price;

}

}

//Book.java

package com.test;

public class Book extends CatalogItem {

private String author;

private int ISBN;

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

super(title, price);

this.author = author;

ISBN = iSBN;

}

public String getAuthor() {

return author;

}

public int getISBN() {

return ISBN;

}

@Override

public String toString() {

return "Title: " + getTitle() + " | Author: "+author + " | Price: " + getPrice() + " ISBN: "+ISBN;

}

}

//AudioBook.java

package com.test;

public class AudioBook extends Book {

private double runningTime;

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

super(title, price, author, iSBN);

this.runningTime = runningTime;

}

public double getRunningTime() {

return runningTime;

}

public double getP() {

return getPrice()*0.90;

}

@Override

public String toString() {

return "Title: " + getTitle() + " | Author: "+getAuthor() + " | Price: " + getP() + " | ISBN: "+getISBN() + " | running time: "+runningTime;

}

}

//DVD.java

package com.test;

public class DVD extends CatalogItem {

private String director;

private int year;

private 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;

}

@Override

public String toString() {

return "Title: " + getTitle() + " | Director: "+director + " | Price: " + getPrice() + " | Year: "+year + " | DvdCode: "+dvdcode;

}

}

//Driver.java

package com.test;

import java.util.ArrayList;

import java.util.Scanner;

public class Driver {

public static ArrayList<Book> booklist = new ArrayList<>();

public static ArrayList<DVD> dvdlist = new ArrayList<>();

public static void display()

{

for(int i=0;i<booklist.size();i++)

{

if(booklist.get(i) instanceof AudioBook)

System.out.println((AudioBook)(booklist.get(i)));

else

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

}

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

for(int i=0;i<dvdlist.size();i++)

{

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

}

}

//method to find book

public static boolean findBook(int isbn)

{

for(int i=0;i<booklist.size();i++)

{

if(booklist.get(i).getISBN() == isbn)

return true;

}

return false;

}

//method to find book

public static boolean findDVD(int dvdcode)

{

for(int i=0;i<dvdlist.size();i++)

{

if(dvdlist.get(i).getDvdcode() == dvdcode)

return true;

}

return false;

}

public static void main(String[] args) {

System.out.println("Welcome to the comets Books and DVDs store(Catalog Section)");

int option;

String title;

double price;

String author;

int isbn;

double runningTime;

String director;

int year;

int dvdcode;

Scanner sc = new Scanner(System.in);

while (true) {

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

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 Store");

option = sc.nextInt();

if(option == 1)

{

System.out.println("Please enter Book isbn");

isbn = sc.nextInt();

if(findBook(isbn))

continue;

System.out.println("Please enter Book title");

title = sc.next();

System.out.println("Please enter Book price");

price = sc.nextDouble();

while(price < 0) {

System.out.println("Please enter Book valid price");

price = sc.nextDouble();

}

System.out.println("Please enter Book author");

author = sc.next();

Book b = new Book(title, price, author, isbn);

booklist.add(b);

}

else if(option == 2)

{

System.out.println("Please enter Audio Book isbn");

isbn = sc.nextInt();

if(findBook(isbn))

continue;

System.out.println("Please enter Audio Book title");

title = sc.next();

System.out.println("Please enter Audio Book price");

price = sc.nextDouble();

while(price < 0) {

System.out.println("Please enter Audio Book valid price");

price = sc.nextDouble();

}

System.out.println("Please enter Audio Book author");

author = sc.next();

System.out.println("Please enter Audio Book running time");

runningTime = sc.nextDouble();

while(runningTime < 0) {

System.out.println("Please enter Audio Book valid running time");

runningTime = sc.nextDouble();

}

AudioBook b = new AudioBook(title, price, author, isbn,runningTime);

booklist.add(b);

}

else if(option == 3)

{

System.out.println("Please enter DVD code");

dvdcode = sc.nextInt();

if(findDVD(dvdcode))

continue;

System.out.println("Please enter DVD title");

title = sc.next();

System.out.println("Please enter DVD price");

price = sc.nextDouble();

System.out.println("Please enter DVD director");

director = sc.next();

System.out.println("Please enter DVD year");

year = sc.nextInt();

DVD d = new DVD(title, price, director, year, dvdcode);

dvdlist.add(d);

}

else if(option == 4)

{

System.out.println("Enter isbn number to delete book");

isbn = sc.nextInt();

boolean remove = false;

for(int i=0;i<booklist.size();i++){

if(booklist.get(i).getISBN() == isbn){

booklist.remove(i);

remove = true;

}

}

if(remove == false)

System.out.println("The Book doesn't exist in catalog");

display();

}

else if(option == 5)

{

System.out.println("Enter dvd code to delete DVD");

dvdcode = sc.nextInt();

boolean remove = false;

for(int i=0;i<dvdlist.size();i++){

if(dvdlist.get(i).getDvdcode() == dvdcode){

dvdlist.remove(i);

remove = true;

}

}

if(remove == false)

System.out.println("The DVD doesn't exist in catalog");

display();

}

else if(option == 6)

{

display();

}

else if(option == 9)

break;

else

System.out.println("This option is not acceptable");

}

}

}

Solutions

Expert Solution

Code

CatalogItem.java


package com.test;

public class CatalogItem {
private String title;
private double price;
public CatalogItem(String title, double price) {
super();
this.title = title;
this.price = price;
}

public String getTitle() {
return title;
}
public double getPrice() {
return price;
}
}

Book.java


package com.test;

public class Book extends CatalogItem {
private String author;
private int ISBN;
public Book(String title, double price, String author, int iSBN) {
super(title, price);
this.author = author;
ISBN = iSBN;
}   

public String getAuthor() {
return author;
}

public int getISBN() {
return ISBN;
}
@Override
public String toString() {
return "Title: " + getTitle() + " | Author: "+author + " | Price: " + getPrice() + " ISBN: "+ISBN;
}
  
}

AudioBook.java


package com.test;

public class AudioBook extends Book {

private double runningTime;
public AudioBook(String title, double price, String author, int iSBN, double runningTime) {
super(title, price, author, iSBN);
this.runningTime = runningTime;
}

public double getRunningTime() {
return runningTime;
}

public double getP() {
return getPrice()*0.90;
}
@Override
public String toString() {
return "Title: " + getTitle() + " | Author: "+getAuthor() + " | Price: " + getP() + " | ISBN: "+getISBN() + " | running time: "+runningTime;
}
}

Dvd.java


package com.test;

public class DVD extends CatalogItem {
private String director;
private int year;
private 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;
}

@Override
public String toString() {
return "Title: " + getTitle() + " | Director: "+director + " | Price: " + getPrice() + " | Year: "+year + " | DvdCode: "+dvdcode;
}
  
}

Drver,java


package com.test;
import java.util.ArrayList;
import java.util.Scanner;
public class Driver
{
public static ArrayList<Book> booklist = new ArrayList<>();
public static ArrayList<DVD> dvdlist = new ArrayList<>();
public static void display()
{
for(int i=0;i<booklist.size();i++)
{
if(booklist.get(i) instanceof AudioBook)
System.out.println((AudioBook)(booklist.get(i)));
else
System.out.println(booklist.get(i));
}
System.out.println("-------------------------------------------------------------------------------");
for(int i=0;i<dvdlist.size();i++)
{
System.out.println(dvdlist.get(i));
}
}
//method to find book
public static boolean findBook(int isbn)
{
for(int i=0;i<booklist.size();i++)
{
if(booklist.get(i).getISBN() == isbn)
return true;
}
return false;
}
//method to find book
public static boolean findDVD(int dvdcode)
{
for(int i=0;i<dvdlist.size();i++)
{
if(dvdlist.get(i).getDvdcode() == dvdcode)
return true;
}
return false;
}
public static void main(String[] args) {
System.out.println("Welcome to the comets Books and DVDs store(Catalog Section)");
int option;
String title;
double price;
String author;
int isbn;
double runningTime;
String director;
int year;
int dvdcode;
Scanner sc = new Scanner(System.in);
while (true) {
System.out.println("Choose from the following option:");
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 Store");
option = sc.nextInt();
if(option == 1)
{
System.out.println("Please enter Book isbn");
isbn = sc.nextInt();
if(findBook(isbn))
continue;
System.out.println("Please enter Book title");
title = sc.next();
System.out.println("Please enter Book price");
price = sc.nextDouble();
while(price < 0) {
System.out.println("Please enter Book valid price");
price = sc.nextDouble();
}
System.out.println("Please enter Book author");
author = sc.next();
Book b = new Book(title, price, author, isbn);
booklist.add(b);
}
else if(option == 2)
{
System.out.println("Please enter Audio Book isbn");
isbn = sc.nextInt();
if(findBook(isbn))
continue;
System.out.println("Please enter Audio Book title");
title = sc.next();
System.out.println("Please enter Audio Book price");
price = sc.nextDouble();
while(price < 0) {
System.out.println("Please enter Audio Book valid price");
price = sc.nextDouble();
}
System.out.println("Please enter Audio Book author");
author = sc.next();
System.out.println("Please enter Audio Book running time");
runningTime = sc.nextDouble();
while(runningTime < 0) {
System.out.println("Please enter Audio Book valid running time");
runningTime = sc.nextDouble();
}
AudioBook b = new AudioBook(title, price, author, isbn,runningTime);
booklist.add(b);
}
else if(option == 3)
{
System.out.println("Please enter DVD code");
dvdcode = sc.nextInt();
if(findDVD(dvdcode))
continue;
System.out.println("Please enter DVD title");
title = sc.next();
System.out.println("Please enter DVD price");
price = sc.nextDouble();
System.out.println("Please enter DVD director");
director = sc.next();
System.out.println("Please enter DVD year");
year = sc.nextInt();
DVD d = new DVD(title, price, director, year, dvdcode);
dvdlist.add(d);
}
else if(option == 4)
{
System.out.println("Enter isbn number to delete book");
isbn = sc.nextInt();
boolean remove = false;
for(int i=0;i<booklist.size();i++){
if(booklist.get(i).getISBN() == isbn){
booklist.remove(i);
remove = true;
}
}
if(remove == false)
System.out.println("The Book doesn't exist in catalog");
display();
}
else if(option == 5)
{
System.out.println("Enter dvd code to delete DVD");
dvdcode = sc.nextInt();
boolean remove = false;
for(int i=0;i<dvdlist.size();i++){
if(dvdlist.get(i).getDvdcode() == dvdcode){
dvdlist.remove(i);
remove = true;
}
}
if(remove == false)
System.out.println("The DVD doesn't exist in catalog");
display();
}
else if(option == 6)
{
display();
}
else if(option == 9)
break;
else
System.out.println("This option is not acceptable");
}
}
}

outputs

There is no errors in you program its runnig well see this outputs.

If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.


Related Solutions

package compstore; public class Desktop{ private String brand; private float price; public Desktop(String brand, float price)...
package compstore; public class Desktop{ private String brand; private float price; public Desktop(String brand, float price) { this.brand = brand; this.price = price; } public String getBrand() { return brand; } public float getPrice() { return price; } } package compstore; public class DeskTopDeals{ // assume proper variables and other methods are here public void dealOfTheDay(Desktop[] items, int numItems){ /**************************** * your code would go here * ****************************/ } } Given the above Desktop class, write code that should go...
package construction; public class Bid{ private String contractor; private float price; public Bid(String contractor, float price)...
package construction; public class Bid{ private String contractor; private float price; public Bid(String contractor, float price) { this.contractor = contractor; this.price = price; } public String getContractor() { return contractor; } public float getPrice() { return price; } } package construction; public class ContractorBids{ // assume proper variables and other methods are here public void winningBid(Bid[] bids, int numBids){ /**************************** * your code would go here * ****************************/ } } You are doing renovations on your building, and multiple contractors...
Add the following private attributes: String publisher String title String ISBN String imageName double price Create...
Add the following private attributes: String publisher String title String ISBN String imageName double price Create getter/setter methods for all data types Create a constructor that takes in all attributes and sets them Remove the default constructor Override the toString() method and return a String that represents the book object that is formatted nicely and contains all information (attributes) In the main class: Create a main method that throws FileNotFoundException Import java.io libraries Import java.util.Scanner Create a loop to read...
package mac286.LinkedLists; public class Postfix { private rStack<String> S; private String inSt; private ourLinkedList<String> inList, outList;...
package mac286.LinkedLists; public class Postfix { private rStack<String> S; private String inSt; private ourLinkedList<String> inList, outList; public Postfix(String s) { S = new rStack<String>(); inSt = s; outList = new ourLinkedList<String>(); inList = new ourLinkedList<String>(); } public void reset(String s) { S = new rStack<String>(); inSt = s; outList = new ourLinkedList<String>(); inList = new ourLinkedList<String>(); } private boolean isOperator(char c) { if(c=='-'||c=='+'||c=='*'||c=='/') return true; return false; } private boolean isParenthesis(char c) { if(c == '(' || c==')') return true;...
Programming Exercise Implement the following class design: class Tune { private:    string title; public:   ...
Programming Exercise Implement the following class design: class Tune { private:    string title; public:    Tune();    Tune( const string &n );      const string & get_title() const; }; class Music_collection { private: int number; // the number of tunes actually in the collection int max; // the number of tunes the collection will ever be able to hold Tune *collection; // a dynamic array of Tunes: "Music_collection has-many Tunes" public: // default value of max is a conservative...
java code ============ public class BankAccount { private String accountID; private double balance; /** Constructs a...
java code ============ public class BankAccount { private String accountID; private double balance; /** Constructs a bank account with a zero balance @param accountID - ID of the Account */ public BankAccount(String accountID) { balance = 0; this.accountID = accountID; } /** Constructs a bank account with a given balance @param initialBalance the initial balance @param accountID - ID of the Account */ public BankAccount(double initialBalance, String accountID) { this.accountID = accountID; balance = initialBalance; } /** * Returns the...
public class Book{     public String title;     public String author;     public int year;    ...
public class Book{     public String title;     public String author;     public int year;     public String publisher;     public double cost;            public Book(String title,String author,int year,String publisher,double cost){        this.title=title;         this.author=author;         this.year=year;         this.publisher=publisher;         this.cost=cost;     }     public String getTitle(){         return title;     }         public String getAuthor(){         return author;     }     public int getYear(){         return year;     }     public String getPublisher(){         return publisher;...
Assume you have created the following data definition class: public class Book {    private String title;...
Assume you have created the following data definition class: public class Book {    private String title;    private double cost;       public String getTitle() { return this.title; }    public double getCost() { return this.cost; }       public void setTitle(String title) {       this.title = title;    } // Mutator to return true/false instead of using exception handling public boolean setCost(double cost) {       if (cost >= 0 && cost < 100) {          this.cost = cost;          return true;       }       else {          return false;       }...
I'm getting an error for this code? it won't compile import java.util.*; import java.io.*; public class...
I'm getting an error for this code? it won't compile import java.util.*; import java.io.*; public class Qup3 implements xxxxxlist {// implements interface    // xxxxxlnk class variables    // head is a pointer to beginning of rlinked list    private node head;    // no. of elements in the list    // private int count; // xxxxxlnk class constructor    Qup3() {        head = null;        count = 0;    } // end Dersop3 class constructor   ...
public class StringNode { private String item; private StringNode next; } public class StringLL { private...
public class StringNode { private String item; private StringNode next; } public class StringLL { private StringNode head; private int size; public StringLL(){ head = null; size = 0; } public void add(String s){ add(size,s); } public boolean add(int index, String s){ ... } public String remove(int index){ ... } } In the above code add(int index, String s) creates a StringNode and adds it to the linked list at position index, and remove(int index) removes the StringNode at position...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT