-
Notifications
You must be signed in to change notification settings - Fork 1
/
Person.java
46 lines (35 loc) · 1.08 KB
/
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
39
40
41
42
43
44
45
46
import java.util.Scanner;
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) {
Scanner scanner = new Scanner(System.in);
Person person = new Person();
System.out.print("Enter person's name: ");
String name = scanner.nextLine();
person.setName(name);
System.out.print("Enter person's age: ");
int age = scanner.nextInt();
person.setAge(age);
System.out.println("\nPerson Details:");
System.out.println("Name: " + person.getName());
System.out.println("Age: " + person.getAge());
scanner.close();
}
}