Java Reference
In-Depth Information
The code is not very object-oriented and does not support information hiding in
the
Alien
class. Rewrite the code so that inheritance is used to represent the
different types of aliens instead of the “type” parameter. This should result in
deletion of the “type” parameter. Also rewrite the
Alien
class to hide the member
variables and create a “
getDamage
” method for each derived class that returns
the amount of damage the alien inflicts. Finally, rewrite the
calculateDamage
method to use
getDamage
and write a
main
method that tests the code.
4.
Define a class called
Administrator
, which is a derived class of the class
SalariedEmployee
in Display 7.5. You are to supply the following additional
instance variables and methods:
An instance variable of type
String
that contains the administrator's title (such
as
"Director"
or
"Vice President"
).
An instance variable of type
String
that contains the administrator's area of
responsibility (such as
"Production"
,
"Accounting"
, or
"Personnel"
).
An instance variable of type
String
that contains the name of this
administrator's immediate supervisor.
Suitable constructors, and suitable accessor and mutator methods.
A method for reading in an administrator's data from the keyboard.
Override the definitions for the methods
equals
and
toString
so they are
appropriate to the class
Administrator
.
Also, write a suitable test program.
5.
Give the definition of a class named
Doctor
whose objects are records for a clinic's
doctors. This class will be a derived class of the class
SalariedEmployee
given in
Display 7.5. A
Doctor
record has the doctor's specialty (such as
"Pediatrician"
,
"Obstetrician"
,
"General Practitioner"
, and so forth; so use the type
String
)
and office visit fee (use type
double
). Be sure your class has a reasonable comple-
ment of constructors, accessor and mutator methods, and suitably defined
equals
and
toString
methods. Write a program to test all your methods.
6.
Create a class called
Vehicle
that has the manufacturer's name (type
String
),
number of cylinders in the engine (type
int
), and owner (type
Person
given
below). Then, create a class called
Truck
that is derived from
Vehicle
and has
the following additional properties: the load capacity in tons (type
double
since
it may contain a fractional part) and towing capacity in pounds (type
int
). Be
sure your class has a reasonable complement of constructors, accessor and muta-
tor methods, and suitably defined
equals
and
toString
methods. Write a pro-
gram to test all your methods.
The definition of the class
Person
is below. Completing the definitions of the
methods is part of this programming project.
public class
Person
{
private
String name;