Lab 9: Classes II
In lab today we will again work on Classes.
We will supply a Book class to them and some driver code, similar to the solution from last week's lab.
Last lab's solution: Book.java
BookDriver.java
The instance variables should all be private.
Be sure to comment out sections of code that don't work before
you turn in your solution, since you get no points if your
program doesn't compile.
-
Stage 1:
Add a method getInput() in the driver to prompt for user input, using this to create a book.
-
Stage 2:
Add a cheaperThan() in the Book class that returns the book that is less expensive. This should be called by an object, with the second object sent as a parameter, similar to the equals() method.
-
Stage 3:
Write the code to prompt the user for 3 instances of book. Use the cheaperThan() method to put them in ascending order according to price, and print them out, cheapest first, most expensive last.
About the Submission:
1. You must work in pairs. Only one of you need to submit the program to Blackboard.
2. Names of both partners should be on top of the java files submitted. Make sure to write your name and netID's in the Submission notes as well.
3. Submit the assignment in the appropriate folder on the blackboard.
4. Submission for the lab assignment will close 10 minutes after the respective lab end time.
Solution:
Book.java
BookDriver.java