Java Reference
In-Depth Information
12. public int getMonth()
{
if ( this .month.equals("January"))
return 1;
else if ( this .month.equals("February"))
return 2;
else if ( this .month.equals("March"))
return 3;
else if ( this .month.equals("April"))
return 4;
else if ( this .month.equals("May"))
return 5;
else if ( this .month.equals("June"))
return 6;
else if ( this .month.equals("July"))
return 7;
else if ( this .month.equals("August"))
return 8;
else if ( this .month.equals("September"))
return 9;
else if ( this .month.equals("October"))
return 10;
else if ( this .month.equals("November"))
return 11;
else if ( this .month.equals("December"))
return 12;
else
{
System.out.println("Fatal Error");
System.exit(0);
return 0; // Needed to keep the compiler happy
}
}
13. The instance variable month contains a string, so we used month with equals . It
would have been just as good to use
getMonth() == otherDate.getMonth()
We used getMonth() with the less-than sign because it is of type int and so works
with the less-than sign. The instance variable month is of type String and does not
work with the less-than sign.
14. Every method should be tested in a program in which every other method in the
testing program has already been fully tested and debugged.
15. All instance variables should be marked private .
Search WWH ::




Custom Search