-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStudent.java
More file actions
84 lines (71 loc) · 2.13 KB
/
Student.java
File metadata and controls
84 lines (71 loc) · 2.13 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package com.yurii.salimov.lesson03.task10;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.InputMismatchException;
import java.util.Scanner;
/**
* @author Yuriy Salimov (yuriy.alex.salimov@gmail.com)
* @version 1.0
*/
public class Student {
private static StudentList list = new StudentList();
private static SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
private static Scanner scan = new Scanner(System.in);
private String name;
private String surname;
private String birth;
public static void add() {
Student st = new Student();
System.out.print("Name = ");
st.setName(scan.nextLine());
System.out.print("Surname = ");
st.setSurname(scan.nextLine());
System.out.print("Birth (dd.MM.yyyy) = ");
st.setBirth(scan.nextLine());
list.add(st);
}
public static void delete() {
try {
System.out.print("Enter the serial number of the student to remove n = ");
int n = scan.nextInt() - 1;
list.delete(n);
} catch (InputMismatchException ex) {
System.out.println("Error: " + ex.getMessage());
}
}
public static void showList() {
list.showAllList();
}
public String getName() {
return name;
}
public void setName(String name) {
try {
this.name = name;
} catch (NullPointerException ex) {
System.out.println("Error: " + ex.getMessage());
}
}
public String getSurname() {
return surname;
}
public void setSurname(String surname) {
try {
this.surname = surname;
} catch (NullPointerException ex) {
System.out.println("Error: " + ex.getMessage());
}
}
public String getBirth() {
return birth;
}
public void setBirth(String birth) {
try {
Date date = sdf.parse(birth);
this.birth = sdf.format(date);
} catch (ParseException ex) {
System.out.println("Date error: " + ex.getMessage());
}
}
}