added play-framework project (#678)

* made changes to java reflection

* removed redundant method makeSound in Animal abstract class

* added project for play-framework article
This commit is contained in:
Egima profile
2016-09-13 18:52:27 +03:00
committed by Grzegorz Piwowarek
parent 334e1b3f83
commit 0835118e85
32 changed files with 1771 additions and 0 deletions
@@ -0,0 +1,47 @@
package models;
public class Student {
private String firstName;
private String lastName;
private int age;
private int id;
public Student(){}
public Student(String firstName, String lastName, int age) {
super();
this.firstName = firstName;
this.lastName = lastName;
this.age = age;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}
@@ -0,0 +1,52 @@
package models;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class StudentStore {
private static StudentStore instance;
private Map<Integer, Student> students = new HashMap<>();
public static StudentStore getInstance() {
if (instance == null)
instance = new StudentStore();
return instance;
}
public Student addStudent(Student student) {
int id = students.size() + 1;
student.setId(id);
students.put(id, student);
return student;
}
public Student getStudent(int id) {
if (students.containsKey(id))
return students.get(id);
return null;
}
public List<Student> getAllStudents() {
return new ArrayList<Student>(students.values());
}
public Student updateStudent(Student student) {
int id=student.getId();
if (students.containsKey(id)) {
student.setId(id);
students.put(id, student);
return student;
}
return null;
}
public boolean deleteStudent(int id) {
if (!students.containsKey(id))
return false;
students.remove(id);
return true;
}
}