-
Notifications
You must be signed in to change notification settings - Fork 1
/
person.java
38 lines (29 loc) · 895 Bytes
/
person.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
class Person {
private String name;
private int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
if (age >= 0 && age <= 150) {
this.age = age;
} else {
System.out.println("Invalid age. Age should be between 0 and 150.");
}
}
public static void main(String[] args) {
Person person = new Person();
person.setName("John Doe");
person.setAge(25);
System.out.println("Person Name: " + person.getName());
System.out.println("Person Age: " + person.getAge());
person.setAge(200); // Invalid age
System.out.println("Updated Person Age: " + person.getAge());
}
}