Please follow the instructions on the first page.
Time limit is 1 hour 20 minutes.
You are to write two programs: Book.java and SitInLab1.java.
You may assume that the input data are correct, so you do not need to do input data validation.
Remember not to create multiple instances of Scanner. One instance of Scanner is sufficient.
The Book class should contain the following data members:
There is no need to add any other data members.
Your Book class should contain at least a default constructor and appropriate accessors and mutators. Even if a particular accessor or mutator might not be needed by SitInLab1.java, you should still include it for completeness.
The default constructor should create a new Book object with the following default values:
You may write another constructor if you wish. Do NOT add any other methods besides the constructor(s), accessors and mutators.
This application is to read in a positive integer which indicates the number of books. For each book, it reads in the title, author, edition, year published and initial price, creates a Book object, and computes the final price in 2009 based on the following.
(You will find that there is actually no absolute need to create the Book object, as the task is very simple. However, please create the Book object as instructed anyway, and use the accessors to retrieve information from the object, even though the information are in the variables that hold the input data. We want to test you on how you use the Book class.)
For each year since its publication, a book's price would depreciate by 10% annually. For example, if a book was published in 2006 at an initial price of $30, then in 2007 it would cost $27, in 2008 it would cost $24.30, and in 2009 it would cost $21.87.
Note the following conditions however:
You are to display the final price in two decimal places.
After all the books' information are read, the program is to count the number of books for each edition.
You may write additional method(s) in SitInLab1.java if you wish.
Refer to the sample runs below and make sure that your program produces the output in exactly the same format, or your output will be deemed wrong.
Sample run #1:
$javac Book.java $javac SitInLab1.java $java SitInLab1 Enter number of books: 3 Book 1 of 3 Enter title: Java Programming Enter author: Thomas Wu Enter edition: 4 Enter year published: 2007 Enter initial price: 30.20 Final price: 24.46 Book 2 of 3 Enter title: Economics Enter author: Raymond Oliviere Enter edition: 1 Enter year published: 2005 Enter initial price: 25 Final price: 20.00 Book 3 of 3 Enter title: The Da Vinci Code Enter author: Dan Brown Enter edition: 1 Enter year published: 2006 Enter initial price: 19.50 Final price: 19.50 Number of edition 1 books: 2 Number of edition 2 books: 0 Number of edition 3 books: 0 Number of edition 4 books: 1 Number of edition 5 books: 0
Sample run #2:
Enter number of books: 1 Book 1 of 1 Enter title: Dawn Enter author: Mary Schutz Enter edition: 3 Enter year published: 2004 Enter initial price: 50.75 Final price: 29.97 Number of edition 1 books: 0 Number of edition 2 books: 0 Number of edition 3 books: 1 Number of edition 4 books: 0 Number of edition 5 books: 0
The following two skeleton programs are available in your working directory.
As usual, your programs will be tested with a number of test data, and 60 marks will be awarded to correctness.
20 marks will be awarded to design. In this case it includes (but not limited to) the following:
20 marks will be awarded to style, which includes (but not limited to) appropriate comments, program description, filling in of your name and discussion group, proper indentation, proper naming of identifiers, etc. For example, if you forget to include your name at the top of your program, 2 marks will be deducted.