-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDay-4.java
More file actions
32 lines (29 loc) · 789 Bytes
/
Day-4.java
File metadata and controls
32 lines (29 loc) · 789 Bytes
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
public class Person {
private int age;
public Person(int initialAge) {
if(initialAge < 0){ // initial age is invalid
System.out.println("Age is not valid, setting age to 0.");
this.age = 0;
}
else{ // set age to valid initial age
this.age = initialAge;
}
}
public void amIOld() {
// Set correct statement to print
String result = "";
if(age >= 18){
result = "You are old.";
}
else if(age >=13){
result = "You are a teenager.";
}
else{
result = "You are young.";
}
System.out.println(result);
}
public void yearPasses() {
// Increment this person's age.
this.age++;
}