-
-
Notifications
You must be signed in to change notification settings - Fork 109
Expand file tree
/
Copy pathDay4:Classvs.Instance.java
More file actions
29 lines (26 loc) · 729 Bytes
/
Copy pathDay4:Classvs.Instance.java
File metadata and controls
29 lines (26 loc) · 729 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
public class Person {
private int age;
public Person(int initialAge) {
// Add some more code to run some checks on initialAge
if(initialAge>=0)
age=initialAge;
else{
age=0;
System.out.println("Age is not valid, setting age to 0.");
}
}
public void amIOld() {
String ans="";
if(age<13)
ans="You are young.";
else if(age<18)
ans="You are a teenager.";
else
ans="You are old.";
// Write code determining if this person's age is old and print the correct statement:
System.out.println(ans);
}
public void yearPasses() {
age++;
// Increment this person's age.
}