Question

Create an Item class, which is the abstract super class of all Items.           Item class...

  1. Create an Item class, which is the abstract super class of all Items.          
  1. Item class includes an attribute, description of type String for every item.

[for eg. Book]                                                            

  1. A constructor to initialize its data member of Item class.              
  2. Override toString() method to return details about the Item class.
  1. Create the ExtraCharge interface with the following details.                      
  1. Declare a constant RATE with value 0.25  
  2. Declare a method called calculateExtraCharge(), which returns a double value.
  1. Create the Book class that extends Item and implements ExtraCharge.     
    1. Book class must include three attributes, title of the book, author of the book and price of book.          [For eg. Java Programming, Joyce, 300]    
    2. Define a constructor that takes appropriate parameters so as to initialize data members of book as well as Item class.           
    3. Implement the ExtraCharge interface method.

[Note: When you override calculateExtraCharge() method, it will return extra charge as per the rate defined [0.25] of book price]

    1. Override toString() method to return details about the Book class which also includes the details of super class.                                
  1. Create ItemTester class to test your application.                  

  1. Now create an object of Book class named it myBook and invoke appropriate methods to store book details.

[All the data must be entered by the user. Use do-while loop to let user enter correct data in case wrong data is entered. Mainly user enter wrong price.].                                                           

  1. List all myBookdetails by invoking appropriate methods.

  1. Use concept of method overloading and overload method methods.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE IN JAVA:

Item.java file:


public abstract class Item {
   String description ;

   public Item(String description) {
      
       this.description = description;
   }

   public String toString() {
       return "Item [description=" + description + "]";
   }
  
}

ExtraCharge.java file:


public interface ExtraCharge {
   final double RATE = 0.25 ;
   double calculateExtraCharge();
}

Book.java file:


public class Book extends Item implements ExtraCharge{
   String title ;
   String author ;
   double price ;
   public Book(String description, String title, String author, double price) {
       super(description);
       this.title = title;
       this.author = author;
       this.price = price;
   }
   public double calculateExtraCharge() {
       return price * RATE ;
   }
  
   public String toString() {
       return "description : " + description + ", title=" + title + ", author=" + author + ", price=" + price ;
   }
  
  
  
}

ItemTester.java file:

import java.util.Scanner ;
public class ItemTester {

   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       String description, title, author ;
       double price ;
       System.out.print("Enter the description : ");
       description = sc.nextLine();
       System.out.print("Enter the title : ");
       title = sc.nextLine();
       System.out.print("Enter the author : ");
       author = sc.nextLine();
       System.out.print("Enter the price : ");
       price = sc.nextDouble();
      
       Book myBook = new Book(description, title, author, price);
       System.out.println("Extra charge : " + myBook.calculateExtraCharge());
       System.out.println(myBook);

   }

}

OUTPUT:

@ Console X <terminated > Item Tester (Java Application) C:\Program Files\ava jdk-13.0.1\bin\javaw.exe (24-Apr-2020, 1:57:32

Add a comment
Know the answer?
Add Answer to:
Create an Item class, which is the abstract super class of all Items.           Item class...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Java Program (PLEASE PROVIDE SCREENSHOT OF THE CODE) Create a class Person which is a super...

    Java Program (PLEASE PROVIDE SCREENSHOT OF THE CODE) Create a class Person which is a super class. The class includes four private String instance variables: first name, last name, social security number, and state. Write a constructor and get methods for each instance variable. Also, add a toString method to print the details of the person. After that create a class Teacher which extends the class, Person. Add a private instance variable to store number of courses. Write a constructor...

  • Need help to create general class Classes Data Element - Ticket Create an abstract class called...

    Need help to create general class Classes Data Element - Ticket Create an abstract class called Ticket with: two abstract methods called calculateTicketPrice which returns a double and getld0 which returns an int instance variables (one of them is an object of the enumerated type Format) which are common to all the subclasses of Ticket toString method, getters and setters and at least 2 constructors, one of the constructors must be the default (no-arg) constructor. . Data Element - subclasses...

  • Question #1 (CLO: 1,2.3) Make a class called Car. Declate its data, model, colour, price Also...

    Question #1 (CLO: 1,2.3) Make a class called Car. Declate its data, model, colour, price Also make a constructor to initialize these data variables. Make a getPrice() method to return price. Make a Child class of Car, called Truck. It has a data variable, weight. Make a constructor that takes all the data variables including weight and those of Car class. Also override getPrice() method, which return 20% discount price if the weight is more than 20,000 else it returns...

  • Create the following program in java please Write a class Store which includes the attributes: store...

    Create the following program in java please Write a class Store which includes the attributes: store name and sales tax rate. Write another class encapsulating a Book Store, which inherits from Store. A Book Store has the following additional attributes: how many books are sold every year and the average price per book. Code the constructor, accessors, mutators, toString and equals method of the super class Store and the subclass Book Store; In the Book Store class, also code a...

  • Java file Name Dog Classes and Methods Create a constructor that incorporates the type, breed, and...

    Java file Name Dog Classes and Methods Create a constructor that incorporates the type, breed, and name variables (do not include topTrick). Note: The type refers to what the breed typically does; for example, a corgi would be a “cattle herding dog.” A Shiba Inu would be a “hunting dog.” Create the setTopTrick() mutator method Dog is parent class Corgi and Driver are subclasses Complete the Corgi class: Using the UML Class diagram, declare the instance variables. Create the two...

  • Create a super class called Store which will have below member variables, constructor, and methods Member...

    Create a super class called Store which will have below member variables, constructor, and methods Member variables: - a final variable - SALES_TAX_RATE = 0.06 - String name; /** * Constructor:<BR> * Allows client to set beginning value for name * This constructor takes one parameter<BR> * Calls mutator method setName to set the name of the store * @param name the name of the store */ /** getName method * @return a String, the name of the store */...

  • 1- Create the base class Book that has the following instance variables, constructor, and methods title...

    1- Create the base class Book that has the following instance variables, constructor, and methods title ( String) isbn ( String) authors (String) publisher (String) edition ( int) published_year (int) Constructor that takes all of the above variables as input parameters. set/get methods ToString method // that return sting representation of Book object. 2- Create the sub class New_Book that is derived from the base class Book and has the following instance variables, constructor, and methods: title ( String) isbn...

  • C# programming 50 pts Question 2:2 1- Create the base class Book that has the following instance variables, constructor, and methods title (String) isbn (String) authors (String) publisher (Strin...

    C# programming 50 pts Question 2:2 1- Create the base class Book that has the following instance variables, constructor, and methods title (String) isbn (String) authors (String) publisher (String) edition ( int) published year (int) Constructor that takes all of the above variables as input parameters. set/get methods ToString method// that return sting representation of Book object. 2-Create the sub class New_Book that is derived from the base class Book and has the following instance variables, constructor, and methods: title...

  • Given a class called Product, Product - id : String - price : double + Product()...

    Given a class called Product, Product - id : String - price : double + Product() + Product(id : String, price : double) + getID() : String + getPrice() : double + toString() : String Assume its toString method will return a string like this: ID: id of this obj Price: $xxx.xx Write a FreshProduce class which extends Product. All instance data members should be private and all constructors and methods should be public unless specified otherwise. This FreshProduce class...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT