Java Reference
In-Depth Information
Display 4.15 A Class for Pet Records (part 2 of 4)
58
public Pet( int initialAge)
59
{
60
name = "No name yet.";
61
weight = 0;
62
if (initialAge < 0)
63
{
64
System.out.println("Error: Negative age.");
65
System.exit(0);
66
}
67
else
68
age = initialAge;
69
}
70
71
public void setAge( int newAge)
72
{
73
if (newAge < 0)
74
{
75
System.out.println("Error: Negative age.");
76
System.exit(0);
77
}
Name and weight are unchanged.
78
else
79
age = newAge;
80
}
81
82
83
84
85
86
public Pet( double initialWeight)
87
{
88
name = "No name yet";
89
age = 0;
90
if (initialWeight < 0)
91
{
92
System.out.println("Error: Negative weight.");
93
System.exit(0);
94
}
95
else
96
weight = initialWeight;
97
}
98
public void setWeight( double newWeight)
99
{
Search WWH ::




Custom Search