-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPerson.java
More file actions
65 lines (58 loc) · 1.73 KB
/
Person.java
File metadata and controls
65 lines (58 loc) · 1.73 KB
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
63
64
65
package Inheritance;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.Scanner;
public class Person {
protected String name;
protected Date age;
protected String birthday;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Date getAge() {
return age;
}
public void setAge(Date age) {
this.age = age;
}
public String getBirthday() {
return birthday;
}
public void setBirthday(String birthday) {
this.birthday = birthday;
}
//constructor
public Person() {
}
public Person(String name, Date age,String birthday) {
this.name = name;
this.age=age;
this.birthday = birthday;
}
public void Input() throws ParseException {
Scanner sc = new Scanner(System.in);
System.out.println("Input name: ");
this.name = sc.nextLine();
System.out.println("Input age:");
/*String pattern = "dd-MM-yy";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
this.age = simpleDateFormat.parse(sc.nextLine());*/
SimpleDateFormat df =new SimpleDateFormat("dd/mm/yyyy");
Date age = df.parse(sc.nextLine());
this.age = age;
//this.age = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss").format(sc.nextLine());
System.out.println("Input birthday:");
this.birthday = sc.nextLine();
// DateTimeFormatter myFormatObj = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss");
// String formattedDate = myDateObj.format(myFormatObj);
// this.birthday.format(myFormatObj);
}
public void ViewDetail() {
System.out.println("Name ="+this.getName()+ " and age ="+this.getAge());
}
}