public class Person implements Roles{
private String id;
private String name;
private String[] skills;
private List<Note> notes;
public Person(String id, String name, String[] skills) {
this.id = id;
this.name = name;
this.skills = skills;
this.notes = new ArrayList<Note>();
}
public String getName() {
return this.name;
}
public String getId() {
return this.id;
}
public String[] getSkills() {
return this.skills;
}
public void setName(String name) {
this.name = name;
}
public void setSkills(String[] skills) {
this.skills = skills;
}
public void addNote(String note, String authorName) {
notes.add(new Note(authorName, note));
}
public String listNotes() {
String result = this.name + " - " + this.id;
for (Note note: notes) {
result += "\n" + note.toString();
}
return result;
}
@Override
public String toString() {
String result = this.name + " - " + this.id;
Arrays.sort(skills);
for (String skill: skills) {
result += "\n- " + skills;
}
return result;
}
@Override
public boolean equals(Object o) {
if (o == null) {
return false;
}
if (o.getClass() != this.getClass()) {
return false;
}
Person Person2 = (Person) o;
return this.id.equals(Person2.getId());
}
@Override
public int hashCode() {
return this.id.hashCode();
}
}
public class Student extends Person implements Roles {
private String registration;
private int year;
public Student(String id, String name, String registration, int year, String[] skills) {
super(id, name, skills);
this.registration = registration;
this.year = year;
}
@Override
public String toString() {
String result = super.name + " - " + super.id + "\nStudent - " + this.registration + " - " + this.year;
Arrays.sort(skills);
for (String skill: skills) {
result += "\n- " + skill;
}
return result;
}
@Override
public String listNotes() {
String result = super.name + " - " + super.id + "\nStudent - " + this.registration + " - " + this.year + "\nNotes:";
for (Note note: notes) {
result += "\n" + note.toString();
}
return result;
}
}
public class Teacher extends Person implements Roles{
private String number;
private String[] subjects;
public Teacher(String id, String name, String number, String[] subjects, String[] skills) {
super(id, name, skills);
this.number = number;
this.subjects = subjects;
}
@Override
public String toString() {
String result = this.name + " - " + this.id + "\nTeacher - " + this.number + " - ";
for (int i = 0; i <= subjects.length - 1; i++) {
if (i == subjects.length - 1) {
result += subjects[i];
break;
}
result += subjects[i] + ", ";
}
Arrays.sort(skills);
for (String skill: skills) {
result += "\n- " + skill;
}
return result;
}
@Override
public String listNotes() {
String result = this.name + " - " + this.id + "\nTeacher - " + this.number + " - ";
for (int i = 0; i <= subjects.length - 1; i++) {
if (i == subjects.length - 1) {
result += subjects[i] + "\n:";
break;
}
result += subjects[i] + ", ";
}
for (Note note: notes) {
result += "\n" + note.toString();
}
return result;
}
}
The system must be able to register people, students and teachers. I created a superclass Person with Student and Teacher subclasses, and an interface to store in a people map.
And now I need a way to change the roles of those already registered people, like a person becoming a teacher, or a student being out of a role.