Java Reference
In-Depth Information
Display 4.13
A Class with Constructors (part 2 of 5)
36
public void setDate( int monthInt, int day, int year)
37
{
38
if (dateOK(monthInt, day, year))
39
{
40
this .month = monthString(monthInt);
The mutator methods, whose names begin with
set , are used to reset the data in an object after
the object has been created using new and a
constructor.
41
this .day = day;
42
this .year = year;
43
}
44
else
45
{
46
System.out.println("Fatal Error");
47
System.exit(0);
48
}
49
}
50
public void setDate(String monthString, int day, int year)
51
{
52
if (dateOK(monthString, day, year))
53
{
54
this .month = monthString;
55
this .day = day;
56
this .year = year;
57
}
58
else
59
{
60
System.out.println("Fatal Error");
61
System.exit(0);
62
}
63
}
64
public void setDate( int year)
65
{
66
setDate(1, 1, year);
67
}
68
public void setYear( int year)
69
{
70
if ( (year < 1000) || (year > 9999) )
71
{
72
System.out.println("Fatal Error");
73
System.exit(0);
74
}
75
else
76
this .year = year;
77
}
Search WWH ::




Custom Search