Question

In: Computer Science

JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the...

JAVA Programming ECLIPSE IDE

1.

Create an abstract class called Book. The class should declare the following variables:
an instance variable that describes the title - String
an instance variable that describes the ISBN - String
an instance variable that describes the publisher - String
an instance variable that describes the price - double
an instance variable that describes the year – integer

Provide a toString() method that returns the information stored in the above variables.

Create the getter and setter methods for each instance variable except price. Provide the necessary constructors. Include an abstract method setPrice(double price) to determine the price for a book. Include an abstract method getGenre() to return the genre of the book.

Create two subclasses called ScienceBook and ChildrenBook.


These subclasses should override the abstract methods setPrice and getGenre of class Book.

Use the following rule for setting the price for a book:
science books will have a 10% discount per each book
children books will have a fixed price (specified by user).

Write a driver program (another class with main method) that uses the above hierarchy. In your driver program you must implement an interaction with the user.
Use showInputDialog method to let the user input book information.
Use showMessageDialog method to display book information including price and type for both science and children books.

Solutions

Expert Solution

Implementation in JAVA;

Code;

import java.util.Scanner;

// Tester Class
public class Tester {

//   driver function
   public static void main(String[] args) {
      
//       showInputDialog method
      
       ScienceBook sb= InputDialog_ScienceBook();
      
       ChildrenBook cb= InputDialog_ChildrenBook();
         
      
      
//       Print details
      
       print_ScienceBook(sb);
  
       print_ChildrenBook(cb);
      

   }
  
//   showMessageDialog of Children book
   public static void print_ChildrenBook(ChildrenBook cb) {
      
System.out.println("\nOutput Details of Children Book: ");
      
       System.out.println(cb.toString());
      
   }
  
//   showMessageDialog of science book
   public static void print_ScienceBook(ScienceBook sb) {
      
   System.out.println("\nOutput Details of Children Book: ");
          
           System.out.println(sb.toString());
          
       }
  
//   showInputDialog method of Science book
   public static ScienceBook InputDialog_ScienceBook() {
      
//       take inputs of Science Book
       Scanner s= new Scanner(System.in);
      
       System.out.println("Enter Details for Science Book \n");
      
       System.out.print("Enter Title of Book : ");
       String title = s.next();
       System.out.print("Enter ISBN of Book : ");
       String isbn = s.next();
       System.out.print("Enter Publisher of Book : ");
       String publisher = s.next();
       System.out.print("Enter price of Book $: ");
       double price = s.nextDouble();
       System.out.print("Enter Year of publishment of Book : ");
       int year = s.nextInt();

       System.out.print("Enter Genre of Book : ");
       String genre = s.next();
      
//       create object and call constructor
       ScienceBook sb= new ScienceBook(title, isbn, publisher, price, year, genre);
      
       return sb;
      
   }
  
  
//   showInputDialog method of Children book
   public static ChildrenBook InputDialog_ChildrenBook() {
      
       Scanner s= new Scanner(System.in);
      
//       take inputs of Children Book
System.out.println("\n\nEnter Details for Children Book \n");
      
       System.out.print("Enter Title of Book : ");
       String title1 = s.next();
       System.out.print("Enter ISBN of Book : ");
       String isbn1 = s.next();
       System.out.print("Enter Publisher of Book : ");
       String publisher1 = s.next();
       System.out.print("Enter price of Book $: ");
       double price1 = s.nextDouble();
       System.out.print("Enter Year of publishment of Book : ");
       int year1 = s.nextInt();

       System.out.print("Enter Genre of Book : ");
       String genre1 = s.next();
      
//       create object and call constructor
      
       ChildrenBook cb= new ChildrenBook(title1, isbn1, publisher1, price1, year1, genre1);
      
       return cb;
      
   }

  
  
}

// Abstract Class book
abstract class Book{
  
  
//   Instance variables
   String title;
  
   String ISBN;
  
   String publisher;
  
   double price;
  
   int year;
  
//   constructor
   public Book(String title, String ISBN, String publisher, double price,int year) {
      
       this.title = title;
       this.ISBN = ISBN;
       this.publisher = publisher;
       this.price=price;
       this.year=year;
      
   }
  
  
//   getters and setters
   public String gettitle() {
       return title;
   }
  
   public void settitle(String title) {
       this.title= title;
   }
  
   public String getISBN() {
       return ISBN;
   }
  
   public void setISBN(String ISBN) {
       this.ISBN= ISBN;
   }
  
   public String getpublisher() {
       return publisher;
   }
  
   public void setpublisher(String publisher) {
       this.publisher= publisher;
   }
  
   public int getyear() {
       return year;
   }
  
   public void setyear(int year) {
       this.year= year;
   }
  
   public double getprice() {
  
       return price;
   }
  
//   to string method
   public String toString() {
      
       String ans="Title : "+title+"\nISBN : "+ISBN+"\nPublisher : "+publisher+"\nYear : "+year;
      
       return ans;
   }
  
  
//   abstract methods
   abstract String getgenre() ;
  
   abstract void setPrice(double price);
  
}


// class ScienceBook extends Book class which implements unimplemented methods
class ScienceBook extends Book{

//   instance variables
   String genre;
     
   int discount = 10;
     
//   call constructor
   public ScienceBook(String title, String ISBN, String publisher, double price, int year, String genre) {
       super(title, ISBN, publisher, price, year);
       this.genre=genre;
      
   }
  
  
   @Override
   String getgenre() {
      
       return genre;
   }

   @Override
   void setPrice(double price) {
      
   this .price = price - (discount*price/100);
      
      
   }
  
  
   @Override
   public String toString() {
  
   setPrice(price);
      
       String ans = super.toString()+"\nPrice $: "+price+" (After 10% discount)" + "\nGenre : "+genre;
      
      
      
       return ans;
      
   }
     
     
     
}


class ChildrenBook extends Book{
     
   String genre;

//   super constructor
   public ChildrenBook(String title, String ISBN, String publisher, double price, int year, String genre) {
       super(title, ISBN, publisher, price, year);
       this.genre=genre;
      
   }

   @Override
   String getgenre() {
  
       return genre;
   }

   @Override
   void setPrice(double price) {
      
       this.price = price;
   }
  
   @Override
   public String toString() {
      
       String ans = super.toString() +"\nPrice $: "+price+" (Fixed price )"+ "\nGenre : "+genre;
      
       return ans;
      
   }
     
     
     
}

SAMPLE OUTPUTS:

// PLEASE THUMBS-UP AND RATE POSITIVELY
If you have any doubt regarding this question please ask me in commnets
// THANK YOU:-)


Related Solutions

JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the...
JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the following variables: an instance variable that describes the title - String an instance variable that describes the ISBN - String an instance variable that describes the publisher - String an instance variable that describes the price - double an instance variable that describes the year – integer Provide a toString() method that returns the information stored in the above variables. Create the getter and...
Using Eclipse IDE Create a Java Program/Class named MonthNames that will display the Month names using...
Using Eclipse IDE Create a Java Program/Class named MonthNames that will display the Month names using an array. 1. Create an array of string named MONTHS and assign it the values "January" through "December". All 12 months need to be in the array with the first element being "January", then "February", etc. 2. Using a loop, prompt me to enter an int variable of 1-12 to display the Month of the Year. Once you have the value, the program needs...
Using eclipse IDE, create a java project and call it applets. Create a package and call...
Using eclipse IDE, create a java project and call it applets. Create a package and call it multimedia. Download an image and save it in package folder. In the package, create a java applet where you load the image. Use the drawImage() method to display the image, scaled to different sizes. Create animation in Java using the image. In the same package folder, download a sound. Include the sound in your applets and make it repeated while the applet executes....
Task #1 The if Statement, Comparing Strings, and Flags (JAVA using Eclipse IDE 14) Create the...
Task #1 The if Statement, Comparing Strings, and Flags (JAVA using Eclipse IDE 14) Create the file PizzaOrder.java. Prompt the user to input the type of pizza that they want to order. In the end, you should print out the final order and price. Here is a sample output. Welcome to May and Adam’s Pizzeria Enter your first name: Amy Pizza Size(inches)     Cost         10            $10.99         12            $12.99         14            $14.99         16            $16.99 What size pizza would you...
Create a Java Program to calculate luggage costs. USING ECLIPSE IDE The Business Rules are: A....
Create a Java Program to calculate luggage costs. USING ECLIPSE IDE The Business Rules are: A. Two bags per person are free. B. The Excess Bag Charge is $75 per bag. The program needs to do the following: 1. In your main method(),    Create integers to store the number of Passengers and also the total number of bags    Prompt for the number of passengers on a ticket.    Prompt for the total number of bags for all passengers...
Create a Java Program to show a savings account balance. using eclipse IDE This can be...
Create a Java Program to show a savings account balance. using eclipse IDE This can be done in the main() method. Create an int variable named currentBalance and assign it the value of 0. Create an int variable named amountToSaveEachMonth. Prompt "Enter amount to save each month:" and assign the result to the int variable in step 2. Create an int variable name numberOfMonthsToSave. Prompt "Enter the number of months to save:" and store the input value into the variable...
. Create a class called Book to represent a book. A Book should include four pieces...
. Create a class called Book to represent a book. A Book should include four pieces of information as instance variables‐a book name, an ISBN number, an author name and a publisher. Your class should have a constructor that initializes the four instance variables. Provide a mutator method and accessor method (query method) for each instance variable. Inaddition, provide a method named getBookInfo that returns the description of the book as a String (the description should include all the information...
Write a Java application that implements the following: Create an abstract class called GameTester. The GameTester...
Write a Java application that implements the following: Create an abstract class called GameTester. The GameTester class includes a name for the game tester and a boolean value representing the status (full-time, part-time). Include an abstract method to determine the salary, with full-time game testers getting a base salary of $3000 and part-time game testers getting $20 per hour. Create two subclasses called FullTimeGameTester, PartTimeGameTester. Create a console application that demonstrates how to create objects of both subclasses. Allow the...
Java programming language should be used Implement a class called Voter. This class includes the following:...
Java programming language should be used Implement a class called Voter. This class includes the following: a name field, of type String. An id field, of type integer. A method String setName(String) that stores its input into the name attribute, and returns the name that was just assigned. A method int setID(int) that stores its input into the id attribute, and returns the id number that was just assigned. A method String getName() that return the name attribute. A method...
(In java language) Write an abstract class called House. The class should have type (mobile, multi-level,...
(In java language) Write an abstract class called House. The class should have type (mobile, multi-level, cottage, etc.) and size. Provide the following methods: A no-arg/default constructor. A constructor that accepts parameters. A constructor that accepts the type of the house and sets the size to 100. All other required methods. An abstract method for calculating heating cost. Come up with another abstract method of your own. Then write 2 subclasses, one for mobile house and one for cottage. Add...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT