generated from athenian-apcs/pet-inheritance-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dog.java
43 lines (36 loc) · 928 Bytes
/
Dog.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
public class Dog extends Pet {
// Instance variable(s)
private String name;
private int age;
private String breed;
//Constructors
public Dog(String name, int age, String breed) {
this.name = name;
this.age = age;
this.breed = breed;
}
public Dog() {
this.name = "Max";
this.age = 1;
this.breed = "Golden Retriever";
}
// makeNoise() method
public void makeNoise() {
System.out.println("Woof!");
}
// toString method
public String toString() {
String str = "Name: " + name + ", Age: " + age + ", Breed:" + breed;
return str;
}
// Getter- already inherited getName and getAge
public String getBreed() {
return this.breed;
}
// Setter
public void setBreed(String breed) {
if (name.trim().length() != 0) {
this.breed = breed;
}
}
}