Hello, here is the assignment:
A book object has three attributes, a title (
String), an ISBN (long), and a price (double).
Part 1:
You are required to design and implement the Book class according to the following specifications:
- Upon the creation of a book object, the object must immediately be initialized with valid values; that is title, ISBN and price. You may assume that ISBN numbers do NOT start with 0 (that is they can start only with digits from 1 to 9).
- Your class should have a copy constructor, so new book objects can be created as exact copies of existing ones.
- The design should allow enough flexibility so that the value of any of these attributes can be modified later on. For example, it should be possible to create a book object with a given price then change its price later on.
- The design should allow the user of the class to obtain the value of any of the attributes individually (i.e. getPrice()).
- The design should also allow the user to view all book information at once using the System.out.print() method. That is, a statement such as: System.out.println(b1); would display all information of book b1.
Hint: Use toString() function.
Part 2:
In this part, you are required to write a public class called BookSearch, which will utilize the Book class created in part 0. In the main method of this class the following must be done:
Create an array of 10 books. All these books must be initialized with proper values; that is: title, price & ISBN. You must use the copy constructor to create some of these objects.
- Ask the user to enter three pieces of information: a book title, a book price, and either Yes or No for a search combination (see details below).
- Read the entered information.
- Depending on whether the user has entered Yes or No for matching combinations, your program will search the array for matching books based on the following rules:
If the user enters Yes (case insensitive) for matching combinations, then your program will search the array and displays all books that have both the title and the price entered by the user.
If the user enters No (or anything different than Yes) for matching combinations, then your program will search the array and displays all books that have either the title entered by the user or the price entered by the user.
If no matches were found, the program must indicate that to the user.
As a general rule, displaying of any prices must be formatted using printf.
Guideline: For part 1 and 2, you will need to create one .java file, called BookSearch.java, which includes the Book class as well as the BookSearch class (this is the public class), which will have the main() function.
Part 3:
For this part, you are required to write a class called ModifyBooks, which is going to utilize the Book class that you have created in part 1. In that part, you required to write a public class, the ModifyBooks class. In the main() method of this class the following must be done:
- Create an array of 10 books; all books in the arrays must be initialized with proper values; that is title, price & ISBN. At least 4 of these books should be created using the copy constructor.
- Change the price of all the objects. You can simply use a for loop and set the prices using any formula (for instance, the prices can be set to i*5 + 100), where i is the loop controller variable. You can use the Random class if you wish.
- Ask the user to enter a title, and ISBN of a book.
Read the title and the ISBN, then go through the entire array looking for books with this title and the same ISBN, and keep track of all of their locations.
- Now you need to adjust the prices of the books. All books that were found with the same title and the same ISBN must be adjusted to have the smallest price that any of them has. An indication must be displayed for every object that is modified.
Here is an example to illustrate the requirements. Assume Arr is the name of the array, and that:
Arr[2] has a book with the following information: “Java 3, ISBN 900700, 112$”, Arr[5] has a book with the following information: “Java 3, ISBN 230680, 56$”, Arr[7] has a book with the following information: “Java 3, ISBN 900700, 83$” , and Arr[9] has a book with the following information: “Java 3, ISBN 900700, 92$”.
If the user enters “Java 3” for the title and 900700 for ISBN, then the program must first keep track of the locations of all books with these information; in this example indices 2, 7 & 9. The program must then modify the prices of these objects to the smallest that any of them has; in this case 83$. Consequently the program will modify Arr[2] & Arr[9]. An indication must be displayed to indicate these modifications, similar to the following: Price of book at index 2 has been modified from 112$ to 82$.
As a general rule, displaying of any prices must be formatted using printf.
Guideline: For part 3, you will need to create one .java file, called ModifyBooks.java, which includes an exact copy of the Book class defined in Part 1, as well as the ModifyBooks class (this is the public class), which will have the main() function.