Advertisement
Guest User

Untitled

a guest
Feb 19th, 2017
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. Class Book
  2.  
  3. has instance data members (all private) String title, String author, int pages, double price.
  4. has a public static int variable named numBooks with an initial value of zero.
  5. has a parameterized constructor that will be used to make a Book object and assign values to its data members, and increment numBooks.
  6. has a no-arg constructor that increments numBooks.
  7. has getters and setters for all instance data members.
  8. has a toString() method that returns a string displaying the state of a Book instance.
  9. Use the numBooks variable to report the number of books instantiated.
  10.  
  11. Class TestBook
  12. This class needs a main method and two more methods.
  13. In main:
  14.  
  15. create an array capable of holding six Book objects.
  16. use the parameterized constructor to specify the data in the first four elements of this array
  17. use the no-arg constructor to create the two remaining books in the array.
  18. process the array with a foreach loop to display the array at this point.
  19. call the finishArray() method with the array as the only argument.
  20. call the reduceBooks() method with the array as the sole argument.
  21. repeat the code needed by Step 4 above.
  22. display the most expensive book after the discounts.
  23.  
  24. In finishArray():
  25.  
  26. this is a void method.
  27. use the setter methods to specify the data in all fields of the last two books in the array.
  28.  
  29. In reduceBooks():
  30.  
  31. this method returns a Book instance.
  32. use a loop (any type) to reduce the price of every book in the array by 40%.
  33. determine the most expensive book after the discounts and return this book to main.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement