[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...
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 */...
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...
Problem: Coffee(Java) Design and implement a program that manages coffees. First, implement an abstract class named Coffee. The Coffee class has three member variables: coffee type(does not mention the data type of the variable coffeeType), price, and store name. The Coffee class has an abstract method name ingredient. Make sure to add all necessary setters and getters as well as other methods. The class Coffee implements an interface HowToMakeDrink. The interface has the following method: public interface HowToMakeDrink { public...
Write the following program in Java. Create an abstract Vehicle class - Vehicle should have a float Speed and string Name, an abstract method Drive, and include a constructor. Create a Tesla class - Tesla inherits from Vehicle. - Tesla has an int Capacity. - Include a constructor with the variables, and use super to set the parent class members. - Override Drive to increase the speed by 1 each time. - Add a toString to print the name, speed,...
Ticket Hierarchy Ticket Abstract Class Create a static variable called nextTicketId. This is an integer representing the next available integer for the ticketId private static int nextTicketId = 1000; getPrice method: Abstract method that returns a double. NOTE: Do not make price an instance variable in Ticket. Noargument constructor: Sets event name to “none”, event location to “none”, and ticket id to 0. Create a constructor that accepts the event name and event location as parameters. Set the ticket Id...