Java Reference
In-Depth Information
Display 4.15
A Class for Pet Records (part 4 of 4)
100
if (newWeight < 0)
101
{
102
System.out.println("Error: Negative weight.");
103
System.exit(0);
104
}
105
else
Name and age are unchanged.
106
weight = newWeight;
107
}
108
public Pet()
109
{
110
name = "No name yet.";
111
age = 0;
112
weight = 0;
113
}
114
public String getName()
115
{
116
return name;
117
}
118
public int getAge()
119
{
120
return age;
121
}
122
public double getWeight()
123
{
124
return weight;
125
}
126 }
Display 4.16
Using Constructors and Set Methods (part 1 of 2)
1 import java.util.Scanner;
2 public class PetDemo
3{
4
public static void main(String[] args)
5
{
(continued)
 
 
Search WWH ::




Custom Search