Question: You design a class named Book. This class needs to have following member variables and member methods: Member Variables private String data field named title

You design a class named Book. This class needs to have following member variables and member methods:

Member Variables

private String data field named title

private double data field name discount that specifies the percentage of sale for a book sale (default is zero)

private double data field name unitPrice (default is 0)

private int data field named quantity (default is 0)

Constructors

Default constructor:

public Book()

public Book(int q, String t) with parameter of quantity and title of the book sale

public Book(int q, String t, double r) (with the quantity q, title t, and discount of r)

Methods

The accessor and mutator methods for all four data fields

A method named calculateSale() to calculate the sale of the book

A method named toString() that returns string description of the computer.

You need to implement a TestBook class. In this Test class, you need to create three Book objects (book1, book2, and book3) using different constructors. Change the value of book1 (created by default) with users input values of title of Java, unit price of 90 dollars, quantity of 52 and discount of 0.1. Get users input for title, quantity and unit price to create book2 with discount of 0.1 using second constructor. After that, get users input for title, quantity and unit price for book3, and change book3s discount to 0.15.

Display objects by invoking their toString method.

Create a class diagram in UML notation.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!