Exercise 5A
Implement a class Bookstore
for representing bookstores having
books in two languages: italian and german. Each Bookstore
object
should maintain the following information:
The Bookstore
class should export to its clients the following
methods:
Bookstore
object with a given
initial number of books. The constructor has two parameters: one indicates
the initial number of books in italian language, another the initial number
of books in german language.addBookI
, which takes one parameter of
type int
and increases the number of books in italian language
by its value.addBookG
, which takes one parameter of
type int
and increases the number of books in german language
by its value.getOverallBooksNumber
, which returns the total number of
books (both in italian and german language) stored in a bookstore.getPercentageOfBooksI
, which returns the percentage of
books in italian language. The required percentage is a real number
(i.e. float
) and is equal
to:getPercentageOfBooksG
, which returns the percentage of
books in german language. The required percentage is a real number
(i.e. float
) and is equal
to:Finally, implement a client class which:
Bookstore
object with a given initial number of
books.Exercise 5B
Plan and implement a class Car
with the following properties:
licensePlate
is a string holding the car's license
number;mileage
is an integer holding the car's total covered
distance in km;acquisitionYear
is an integer holding the year the car was
first bought;basePrice
is a double holding the car's base price when it
was first bought;owner
is the current car's owner.
The class Car
should define the following methods:
mileage
to 0
and owner
to null
;addToMileage
that increments mileage
by an integer value, passed as parameter;setOwner
that sets the owner
field to
a string value, passed as parameter.
Furthermore, design and implement a client class with a static method
getCurrentValue
that computes the car's current value, given
a car object and the current year. Use the equation:
pow
method from the java.lang.Math
package.