Java Reference
In-Depth Information
Display 4.11 Overloading Method Names (part 2 of 2)
39
private boolean dateOK( int monthInt, int dayInt, int yearInt)
40
{
41
return ( (monthInt >= 1) && (monthInt <= 12) &&
Two different
methods named
dateOK.
42
(dayInt >= 1) && (dayInt <= 31) &&
43
(yearInt >= 1000) && (yearInt <= 9999) );
44
}
45
private boolean dateOK(String monthString, int dayInt, int yearInt)
46
{
47
return ( monthOK(monthString) &&
48
(dayInt >= 1) && (dayInt <= 31) &&
49
(yearInt >= 1000) && (yearInt <= 9999) );
50
}
51
private boolean monthOK( String month)
52
{
53
return (month.equals("January") || month.equals("February") ||
54
month.equals("March") || month.equals("April") ||
55
month.equals("May") || month.equals("June") ||
56
month.equals("July") || month.equals("August") ||
57
month.equals("September") || month.equals("October") ||
58
month.equals("November") || month.equals("December") );
59
}
60 public void readInput()
61 {
62 boolean tryAgain = true ;
63 Scanner keyboard = new Scanner(System.in);
64 while (tryAgain)
65 {
66 System.out.println("Enter month, day, and year.");
67 System.out.println("Do not use a comma.");
68 String monthInput = keyboard.next();
69 int dayInput = keyboard.nextInt();
70 int yearInput = keyboard.nextInt();
71 if (dateOK(monthInput, dayInput, yearInput) )
72 {
73 setDate(monthInput, dayInput, yearInput);
74 tryAgain = false ;
75 }
76 else
77 System.out.println("Illegal date. Reenter input.");
78 }
79 }
<The rest of the methods are the same as in Display 4.9, except that
the parameter to equals and precedes is, of course, of type DateSixthTry .>
80
}
 
Search WWH ::




Custom Search