Skip to content
Snippets Groups Projects
Commit 95087013 authored by Daniele Rossi's avatar Daniele Rossi
Browse files

R1

parent 40729d26
Branches main
No related merge requests found
Pipeline #31365 failed with stage
in 5 seconds
package it.polito.med;
public class Doctor {
private String id;
private String name;
private String surname;
private String speciality;
public Doctor(String id, String name, String surname, String speciality) {
this.id = id;
this.name = name;
this.surname = surname;
this.speciality = speciality;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSurname() {
return surname;
}
public void setSurname(String surname) {
this.surname = surname;
}
public String getSpeciality() {
return speciality;
}
public void setSpeciality(String speciality) {
this.speciality = speciality;
}
}
package it.polito.med;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class MedManager {
List<String> specialitiesCentre = new ArrayList<>();
Map<String, Doctor> doctors = new HashMap<>();
/**
* add a set of medical specialities to the list of specialities
* offered by the med centre.
......@@ -15,7 +21,11 @@ public class MedManager {
* @param specialities the specialities
*/
public void addSpecialities(String... specialities) {
for(String s:specialities){
if(!specialitiesCentre.contains(s)){
specialitiesCentre.add(s);
}
}
}
/**
......@@ -24,7 +34,7 @@ public class MedManager {
* @return list of specialities
*/
public Collection<String> getSpecialities() {
return null;
return specialitiesCentre;
}
......@@ -38,6 +48,14 @@ public class MedManager {
* @throws MedException in case of duplicate id or non-existing speciality
*/
public void addDoctor(String id, String name, String surname, String speciality) throws MedException {
if(doctors.containsKey(id) || !specialitiesCentre.contains(speciality)){
throw new MedException();
}
else{
Doctor d = new Doctor(id, name, surname, speciality);
doctors.put(id, d);
}
}
......@@ -48,7 +66,7 @@ public class MedManager {
* @return the list of doctor ids
*/
public Collection<String> getSpecialists(String speciality) {
return null;
return doctors.values().stream().filter(p->p.getSpeciality().equals(speciality)).map(Doctor::getId).toList();
}
/**
......@@ -58,7 +76,7 @@ public class MedManager {
* @return the name
*/
public String getDocName(String code) {
return null;
return doctors.get(code).getName();
}
/**
......@@ -68,7 +86,7 @@ public class MedManager {
* @return the surname
*/
public String getDocSurname(String code) {
return null;
return doctors.get(code).getSurname();
}
/**
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment