-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnimal.java
57 lines (51 loc) · 939 Bytes
/
Animal.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
/*
* Created by Noah Shaw
*/
public class Animal {
//Attributes
private String name;
private double weight;
//Constructors
public Animal() //Default
{
this.name = "Bob";
this.weight = 1.0;
}
public Animal(String aName, double aWeight) //Parameter
{
this.setName(aName);
this.setWeight(aWeight);
}
//Accessors
public String getName()
{
return this.name;
}
public double getWeight()
{
return this.weight;
}
//Mutators
public void setName(String aName)
{
this.name = aName;
}
public void setWeight(double aWeight)
{
if(aWeight > 0)
{
this.weight = aWeight;
}
}
//Methods
public String toString()
{
return "Name: "+this.name+" Weight: "+this.weight;
}
public boolean equals(Animal aAnimal)
{
return aAnimal != null &&
this.name.equalsIgnoreCase(aAnimal.getName()) &&
this.weight == aAnimal.getWeight();
}
}