Java Reference
In-Depth Information
4. a.
Example 8-8 defined the
class
Person
to store the name of a person.
The methods that we included merely set the name and print the name
of a person. Redefine the
class
Person
so that, in addition to what the
existing
class
does, you can:
i.
Set the last name only.
ii.
Set the first name only.
iii.
Set the middle name.
iv.
Check whether a given last name is the same as the last name of this
person.
v.
Check whether a given first name is the same as the first name of
this person.
vi.
Check whether a given middle name is the same as the middle
name of this person.
b.
Add the method
equals
that returns true if two objects contain the
same first, middle, and last name.
c.
Add the method
makeCopy
that copies the instance variables of a
Person
object into another
Person
object.
d.
Add the method
getCopy
that creates and returns the address of the
object, which is a copy of another
Person
object.
e.
Add the copy constructor.
f.
Write the definitions of the methods of the
class
Person
to implement
the operations for this
class
.
g.
Write a program that tests various operations of the
class
Person
.
5.
Redo Example 7-3, Chapter 7, so that it uses the
class
RollDie
to roll a die.
6.
Write the definition of a
class
,
swimmingPool
, to implement the proper-
ties of a swimming pool. Your class should have the instance variables to
store the length (in feet), width (in feet), depth (in feet), the rate (in gallons
per minute) at which the water is filling the pool, and the rate (in gallons per
minute) at which the water is draining from the pool. Add appropriate
constructors to initialize the instance variables. Also add member functions,
to do the following: Determine the amount of water needed to fill an empty
or partially filled pool; the time needed to completely or partially fill the
pool, or empty the pool; add water or drain for a specific amount of time.
7.
The equation of a line in standard form is ax + by
¼
c, where a and b both
cannot be zero, and a, b, and c are real numbers. If b
6¼
0, then -a / b is the
slope of the line. If a
¼
0, then it is a horizontal line, and if b
¼
0, then it is a
vertical line. The slope of a vertical line is undefined. Two lines are parallel if
they have the same slope or both are vertical lines. Two lines are perpendi-
cular if one of the lines is horizontal and another is vertical, or if the product
of their slopes is -1. Design the
class
Line
to store a line. To store a line,
Search WWH ::
Custom Search