[for eg. Book]
[Note: When you override calculateExtraCharge() method, it will return extra charge as per the rate defined [0.25] of book price]
[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.].
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:

Create an Item class, which is the abstract super class of all Items. Item class...
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 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 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 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 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 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 ( 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 (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() + 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...