Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

pleas read the qustin and solv step by step Write a java program that do the following: Create a class named Book that consists of

pleas read the qustin and solv step by step

Write a java program that do the following:

Create a class named Book that consists of the following:

Three instance data members of private access modifier:

bookId: represents the serial No. of the book and its data type is integer.

bookName: represents the name of the book and its data type is string.

bookPrice: represents the price of the book and its data type is double.

One static data member of public access modifier:

noOfBooks: keeps track of the number of books objects that are created from the Book class. Its type is integer.

.

Member methods as follows:

Default constructor to initialize the bookId to 1 , bookName to No-Name, and the bookPrice to 1.

Parameterized constructor that receives values for the following data members (bookId, bookName, and bookPrice), then it sets the received values in the class data members.

Create a method named setBookPrice that sets a value in the bookPrice data member. Be sure that the value is nonnegative, otherwise store 0 in bookPrice.

Create a method named getBookPrice that returns the value of the bookPrice.

Create a method named calculateActualPrice that returns the price of the book + tax according to the following equation: bookPrice + (bookPrice * 16%).

Create a method named calculateCostLevel that returns a string representing the actual book cost based on the following:

If the books cost is between 1$ and 75$ return Its affordable!

If the books cost is between 76$ and 100$ return A little bit high but still you can buy it!

Otherwise return High price!.

Create a method named showBookDetails that prints the values of the data members in the following format:

Example 1: If the values in the created object is (id = 12345, name = C++, price = 150)

The Book id is 12345 and its name is C++.

The Book actual cost is : 174$

High price!.

Example 2: If the values in the created object is (id = 222, name = Math, price = 40)

The Book id is 222 and its name is Math.

The Book actual cost is: 46.4$

Its affordable!

Write a Demo class that contains the main method.

In the main method do the following:

Create an object of the Book class named b1 using the default constructor.

Create another object of the Book class named b2 using the parameterized constructor. Ask the user to input the bookId, bookName, and bookPrice.

Call the method setBookPrice for the b1 object to set the price of that object to be 250.

Print the value of the noOfBooks static data member.

Call the showBookDetails method using the object b1.

Call the showBookDetails method using the object b2.

Good Luck J

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Solaris 11.2 System Administration (oracle Press)

Authors: Harry Foxwell

1st Edition

007184421X, 9780071844215

More Books

Students also viewed these Databases questions

Question

Different formulas for mathematical core areas.

Answered: 1 week ago

Question

Understand how to design effective service guarantees.

Answered: 1 week ago