| RHS => Allan => Basic Programming => Exercises => Book |
Updated:
02/02/2004 23:36 WebMaster: allanhn@rhs.dk |
Book
You are to develop a program, which can handle registrations
of book-data in the Fantasy Library.
For a start we define a simple version of the class
Book:
Datafields:
private String title
private int price
(note that the price is in DKK)Constructors
public Book(String aTitle):
public Book(String aTitle, int aPrice)
Methods operating on the data fields
public void setTitle(String aTitle)
public String getTitle()
public void setPrice (int aPrice)
public int getPrice()
public String bookData
Question 1: Worker class
Create a class Book with the mentioned data fields, two constructors and the
methods.
Compile it.
Tip: Very similar to Person class !!
Question 2: Application class
Now to write an application class BookApp using objects
of the class Book with the usual main method.
The BookApp class must show the construction
of several books, use of the methods and print out the book data.
Tip: Very similar to PersonApp class !!
Question 3 Price
In the Book class declare a new method, which can calculate the price in US$.
The parameter to the method must be the exchange rate.
Thus the method resembles
the template:
double priceInDollar(double exchangeRate) {…
Test the call of this method in your BookApp class.
Question 4 Genre
Eexpand the Book class with a data field for the genre of the Book.
Create a new constructor, which can initialise: title, price, and genre.
Do not change the other constructors !!
Change bookData method to take the genre into account.
In BookApp use this constructor and print out the new book data.