-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReformatory.java
108 lines (78 loc) · 2.44 KB
/
Reformatory.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
* DO TOT TOUCH THIS CLASS!
*/
public class Person {
private String name;
private int age;
private int height;
private int weight;
public Person(String name, int age, int height, int weight) {
this.name = name;
this.age = age;
this.height = height;
this.weight = weight;
}
public void becomeOlder() {
this.age++;
}
public boolean adult() {
return this.age >= 18;
}
public double weightIndex() {
double heightInMeters = this.height / 100.0;
return this.weight / (heightInMeters * heightInMeters);
}
public void setHeight(int height) {
this.height = height;
}
public int getHeight() {
return this.height;
}
public class Reformatory {
private int totalTimesMeasured;
public Reformatory() {
this.totalTimesMeasured = 0;
}
public int weight(Person person) {
// return the weight of the person
this.totalTimesMeasured++;
return person.getWeight();
}
public void feed(Person person) {
int temporaryWeight = person.getWeight();
person.setWeight(temporaryWeight + 1);
}
public int totalWeightsMeasured() {
return this.totalTimesMeasured;
}
}
public class Main {
public static void main(String[] args) {
// write here test code
Reformatory eastHelsinkiReformatory = new Reformatory();
Person brian = new Person("Brian", 1, 110, 7);
Person pekka = new Person("Pekka", 33, 176, 85);
System.out.println("total weights measured "+eastHelsinkiReformatory.totalWeightsMeasured());
eastHelsinkiReformatory.weight(brian);
eastHelsinkiReformatory.weight(pekka);
System.out.println("total weights measured "+eastHelsinkiReformatory.totalWeightsMeasured());
eastHelsinkiReformatory.weight(brian);
eastHelsinkiReformatory.weight(brian);
eastHelsinkiReformatory.weight(brian);
eastHelsinkiReformatory.weight(brian);
System.out.println("total weights measured "+eastHelsinkiReformatory.totalWeightsMeasured());
}
}
public int getWeight() {
return this.weight;
}
public void setWeight(int weight) {
this.weight = weight;
}
public String getName() {
return this.name;
}
public String toString() {
return this.name + " I am " + this.age + " years old, my weight index is " + this.weightIndex();
}
}