Java Reference
In-Depth Information
SalariedEmployee otherSalariedEmployee =
(SalariedEmployee)otherObject;
return
(
super
.equals(otherSalariedEmployee)
&& (salary == otherSalariedEmployee.salary));
}
}
21.
A version of the
Date
class with this definition of
equals
is in the subdirectory
improvedEquals
of the
ch07
directory on the accompanying CD.
extra code
on CD
public boolean
equals(Object otherObject)
{
if
(otherObject ==
null
)
return false
;
else if
(getClass() != otherObject.getClass())
return false
;
else
{
Date otherDate =
(Date)otherObject;
return
( month.equals(otherDate.month)
&& (day == otherDate.day)
&& (year == otherDate.year) );
}
}
22.
Not the same class.
23.
The following is included in the definition of
EnhancedStringTokenizer
on the
accompanying CD.
extra code
on CD
public
Object nextElement()
{
String token =
super
.nextToken();
a[count] = token;
count++;
return
(Object)token;
}
Programming Projects
Many of these Programming Projects can be solved using AW's CodeMate.
To access these please go to:
www.aw-bc.com/codemate
.
1.
Define a class named
Payment
that contains a member variable of type
double
that stores the amount of the payment and appropriate accessor and mutator
methods. Also create a method named
paymentDetails
that outputs an English
sentence to describe the amount of the payment.