-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cat.java
63 lines (61 loc) · 1.17 KB
/
Cat.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
public class Cat { //Define the class
//Instance variables
private String name;
private double weight;
private int numLegs;
//Constructors
public Cat() //Default
{
this.name = "no name yet";
this.weight = 1.0;
this.numLegs = 4;
}
public Cat(String aName, double aWeight, int aNumlegs) //Parameterized constructor
{
//TODO Call mutators
}
//Accessors
public String getName()
{
return this.name;
}
public double getWeight()
{
return this.weight;
}
public int getNumLegs()
{
return this.numLegs;
}
//Mutators
public void setName(String aName)
{
this.name = aName;
}
public void setWeight(double aWeight)
{
if(aWeight > 0.0)
{
this.weight = aWeight;
}
}
public void setNumLegs(int aNumLegs)
{
if(aNumLegs >= 0 && aNumLegs <= 4)
{
this.numLegs = aNumLegs;
}
}
//Other methods
public String toString()
{
return this.name + " " + this.weight + " " + this.numLegs;
}
public boolean equals(Cat thatCat)
{
return thatCat != null &&
this.name.equals(thatCat.getName()) &&
this.weight == thatCat.getWeight() &&
this.numLegs == thatCat.getNumLegs();
}
}