-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtutorial_31.java
68 lines (61 loc) · 1.38 KB
/
tutorial_31.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
64
65
66
67
68
/**
* Driver class
*/
class PetStore {
public static void main(String[] args) {
Dog lab = new Dog();
lab.setName("Barker");
lab.birthday();
System.out.println(
lab.getName() + " is " + lab.getAge()
);
}
}
/**
* Dog class
*/
class Dog {
private String name;
private String color;
private int age;
private double height;
private boolean male;
//
public Dog() {
name = "";
color = "";
age = 0;
height = 0.5;
male = true;
}
//
public Dog(String n, String c, boolean g) {
name = n;
color = c;
age = 0;
height = 0.5;
male = g;
}
// change name of dog
public void setName(String n) {
name = n;
}
// get the name of the dog
public String getName() {
return name;
}
// get age of the dog
public int getAge() {
// return the human equivalent age of the dog instead of its actual age
int humanAge = calcHumanAge(age);
return humanAge;
}
// update age by 1 everytime method is called
public void birthday() {
age++;
}
// a helper function inside my class that no one outside of the class can use
private int calcHumanAge(int dogAge) {
return (dogAge * 7);
}
}