Question: 1) Write a Java program that has a class Book in which there are 3 variables: title (string), author (string) and price in AED (float).

 1) Write a Java program that has a class Book in

1) Write a Java program that has a class Book in which there are 3 variables: title (string), author (string) and price in AED (float). The data should be unreachable from outside the class. The class hasa full constructor to initialize all the class variables and a copy constructor. It also has a getter and setter methods for the variable price only, a toString method that returns a string similar to the sample output below, a compareTo method that returns an int with the difference in price, and a displayBook method that uses the toString method to print the details of the object on the screen. Also the class has a driver method that instantiates 2 Book objects (as shown in the output below). The objects will be printed on the standard output using the displayBook method and then compared using the compareTo method to print which book is cheaper. Create a third object using the copy constructor and use the second book as a parameter. Print the third book on the screen using the displayBook method

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!