Cerner Corporation Interview Question
Software EngineersCountry: United States
Interview Type: In-Person
public class Patient {
private String name;
private int age;
private List<Allergy> allergyList;
private List<Disease> diseaseList;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public List<Allergy> getAllergyList() {
return allergyList;
}
public void setAllergyList(List<Allergy> allergyList) {
this.allergyList = allergyList;
}
public List<Disease> getDiseaseList() {
return diseaseList;
}
public void setDiseaseList(List<Disease> diseaseList) {
this.diseaseList = diseaseList;
}
}
------------------------------------------------------------------------------------------------------
public class Allergy {
private String allergyName;
private String severity;
public String getAllergyName() {
return allergyName;
}
public void setAllergyName(String allergyName) {
this.allergyName = allergyName;
}
public String getSeverity() {
return severity;
}
public void setSeverity(String severity) {
this.severity = severity;
}
}
---------------------------------------------------------------------------------------------------------------------
public class Disease {
private String diseaseName;
}
---------------------------------------------------------------------------------------------------------------------
public class PatientHealthInfo {
public static void main(String[] args) {
Patient pt = new Patient();
pt.setName("jack");
Allergy al = new Allergy();
al.setAllergyName("rashes");
al.setSeverity("medium");
Allergy al1 = new Allergy();
al1.setAllergyName("swelling");
al1.setSeverity("medium");
List<Allergy> allergyList = new ArrayList<Allergy>();
allergyList.add(al);
allergyList.add(al1);
pt.setAllergyList(allergyList);
String str = patient(pt);
System.out.println(" Result is :: " + str);
}
public static String patient(Patient pt){
if(pt.getAllergyList().size() > 0){
return "allergy";
}
else if (pt.getDiseaseList().size() > 0){
return "diease";
}
return null;
}
}
Maybe you can include some enums rather than String datatypes to aboud any typing errors. For example, an enum for severity can have constant values like LOW,HIGH,MODERATE . I had the same experience in an interview. The interviewer wanted me to be more creative with methods and asked to avoid using String datatype at all
public class PatientHealthInfo {
- Apurva August 14, 2015public static void main(String[] args) {
Patient pt = new Patient();
pt.setName("jack");
Allergy al = new Allergy();
al.setAllergyName("rashes");
al.setSeverity("medium");
Allergy al1 = new Allergy();
al1.setAllergyName("sweling");
al1.setSeverity("medium");
List<Allergy> allergyList = new ArrayList<Allergy>();
allergyList.add(al);
allergyList.add(al1);
pt.setAllergyList(allergyList);
String str = patient(pt);
System.out.println(" Result is :: " + str);
}
public static String patient(Patient pt){
if(pt.getAllergyList().size() > 0){
return "allergy";
}
else if (pt.getDiseaseList().size() > 0){
return "diease";
}
return null;
}
}
====================
public class Patient {
private String name;
private int age;
private List<Allergy> allergyList;
private List<Disease> diseaseList;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public List<Allergy> getAllergyList() {
return allergyList;
}
public void setAllergyList(List<Allergy> allergyList) {
this.allergyList = allergyList;
}
public List<Disease> getDiseaseList() {
return diseaseList;
}
public void setDiseaseList(List<Disease> diseaseList) {
this.diseaseList = diseaseList;
}
}
=================================================
public class Allergy {
private String allergyName;
private String severity;
public String getAllergyName() {
return allergyName;
}
public void setAllergyName(String allergyName) {
this.allergyName = allergyName;
}
public String getSeverity() {
return severity;
}
public void setSeverity(String severity) {
this.severity = severity;
}
}
====================================
public class Disease {
private String diseaseName;
}