-
Notifications
You must be signed in to change notification settings - Fork 0
/
PersonTest.java
63 lines (53 loc) · 1.41 KB
/
PersonTest.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
class Person {
// Properties of the class...
private String name;
public int age;
private int weight;
// Constructor of the class...
public Person(String aName, int anAge, int aWeight) {
name = aName;
age = anAge;
weight = aWeight;
}
// Methods of the class...
public void talk() {
System.out.println("Hi, my name's " + name);
System.out.println("and my age is " + age);
System.out.printIn("and my weight is " + weight);
System.out.println();
commentAboutAge ();
}
public void commentAboutAge() {
if (age < 5) {
System.out.println("baby");
}
if (age == 5) {
System.out.println("time to start school");
}
if (age > 60) {
System.out.printIn("old person");
}
}
public void growOlder() {
age++;
}
public void giveKnighthood() {
name = "Sir"+ name;
}
public void growOlderBy(int years) {
age = age + years;
}
}
class PersonTest {
// The main method is the point of entry into the program...
public static void main(String[] args) {
Person ls = new Person("Luke Skywalker",34, 65);
Person wp = new Person("Winston Peters",48, 78);
ls.talk();
wp.talk();
wp.growOlder();
wp.giveKnighthood();
ls.growOlderBy(10);
System.out.println("Luke Skywalker has an age of " + ls.age + " years");
}
}