-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStudentManagement.java
More file actions
166 lines (131 loc) · 4.29 KB
/
StudentManagement.java
File metadata and controls
166 lines (131 loc) · 4.29 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
package studentmanagement;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import java.util.List;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class StudentManagement {
public static void main(String[] args) {
ClassPathXmlApplicationContext context=new ClassPathXmlApplicationContext("Spring-context.xml");
context.start();
StudentManagementSystem sms=(StudentManagementSystem)context.getBean("sms");
sms.registerStudent((Student)context.getBean("student1"));
sms.listAllStudents();
sms.registerStudent((Student)context.getBean("student2"));
sms.registerStudent((Student)context.getBean("student3"));
sms.listAllStudents();
}
}
class Student {
private String firstName,lastName,address;
private int index,level;
private double gpa;
public Student(){
}
public Student(int index,String first,String last,String addr,int level,double gpa){
this.index=index;
this.firstName=first;
this.lastName=last;
this.address=addr;
this.level=level;
this.gpa=gpa;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public int getIndex() {
return index;
}
public void setIndex(int index) {
this.index = index;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public double getGpa() {
return gpa;
}
public void setGpa(double gpa) {
this.gpa = gpa;
}
public int getLevel() {
return level;
}
public void setLevel(int level) {
this.level = level;
}
}
interface StudentRepository {
public void saveStudent(Student st);
public Student findStudent(int index);
public void upadateStudent(Student st);
public void deleteStudent(int index);
public List<Student> findAll();
}
class SimpleStudentRepository implements StudentRepository{
private HashMap<Integer,Student> students;
public SimpleStudentRepository(){
students=new HashMap<Integer, Student>();
}
public void saveStudent(Student st) {
students.put(st.getIndex(), st);
}
public Student findStudent(int index) {
return students.get(index);
}
public void upadateStudent(Student st) {
deleteStudent(st.getIndex());
saveStudent(st);
}
public void deleteStudent(int index) {
if(findStudent(index)!=null){
students.remove(index);
}
else{
System.out.println("Student not found!");
}
}
public List<Student> findAll() {
List<Student> temp=new ArrayList<Student>(students.values());
return temp;
}
}
class StudentManagementSystem {
private SimpleStudentRepository repo;
public StudentManagementSystem(){
repo=new SimpleStudentRepository();
}
public StudentManagementSystem(SimpleStudentRepository r){
repo=r;
}
public void listAllStudents(){
List<Student> temp=repo.findAll();
System.out.println("---------------------------------------------------------------------------------");
System.out.println("Student Details");
System.out.println("---------------------------------------------------------------------------------");
for(int i=0;i<temp.size();i++){
System.out.print(temp.get(i).getIndex());
System.out.print("\t"+temp.get(i).getFirstName());
System.out.print(" "+temp.get(i).getLastName());
System.out.print("\t"+temp.get(i).getAddress());
System.out.print("\t\tLevel:"+temp.get(i).getLevel());
System.out.println("\t\tGPA:"+temp.get(i).getGpa());
}
System.out.println("---------------------------------------------------------------------------------");
}
public void registerStudent(Student st){
repo.saveStudent(st);
}
}