Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2014
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. public class HospitalManager{
  2. public static Patient patientListStart = null;
  3. private static int patientCount = 0;
  4.  
  5.  
  6.  
  7. public static void launch() {
  8. Patient firstPatient = new Patient ("John", 33, "Tuberculosis");
  9. patientListStart = firstPatient;
  10. }
  11.  
  12. public void prettyPrint() {
  13. Patient current = patientListStart;
  14. while (current != null) {
  15. System.out.print(current);
  16. current = current.nextPatient;
  17. }
  18. System.out.println();
  19. }
  20.  
  21. public static void main (String[] args){
  22. HospitalManager hospitalManager = new HospitalManager();
  23. hospitalManager.launch();
  24. Patient eightPatient = new Patient("Maryann", 76, "Meningitis");
  25. hospitalManager.addPatient(eightPatient);
  26. Patient secondPatient = new Patient("Mary", 66, "Meningitis");
  27. hospitalManager.addPatient(secondPatient);
  28. Patient thirdPatient = new Patient("Lily", 65, "Tuberculosis");
  29. hospitalManager.addPatient(thirdPatient);
  30. Patient fourthPatient = new Patient("Louis", 26, "Meningitis");
  31. hospitalManager.addPatient(fourthPatient);
  32. Patient fifthPatient = new Patient("Carlos", 15, "Meningitis");
  33. hospitalManager.addPatient(fifthPatient);
  34. Patient sixthPatient = new Patient("Peter", 36, "Tuberculosis");
  35. hospitalManager.addPatient(sixthPatient);
  36. Patient seventhPatient = new Patient("Ann", 36, "Meningitis");
  37. hospitalManager.addPatient(seventhPatient);
  38. Patient ninePatient = new Patient("Kelly", 33, "Tuberculosis");
  39. hospitalManager.deletePatient(eightPatient);
  40.  
  41. /*Patient nextP = hospitalManager.patientListStart;
  42.  
  43. while(nextP != null)
  44. {
  45. System.out.println(nextP);
  46. nextP = nextP.nextPatient;
  47. }
  48.  
  49.  
  50. while(nextP != null) {
  51. System.out.println(nextP);
  52. nextP = nextP.nextPatient;
  53. } */
  54.  
  55. }
  56.  
  57.  
  58. public void addPatient(Patient newPatient) {
  59. if (this.patientListStart == null) {
  60. this.patientListStart = newPatient;
  61. } else {
  62. this.patientListStart.addPatient(newPatient);
  63. }
  64. }
  65.  
  66. public boolean deletePatient (Patient patient) {
  67. if(this.patientListStart == null) {
  68. return false;
  69. } else if (this.patientListStart.name.equals(patient.name)) {
  70. this.patientListStart = patientListStart.nextPatient;
  71. return true;
  72. } else {
  73. return this.patientListStart.deletePatient(patient);
  74. }
  75. }
  76.  
  77. public int countPatient() {
  78. Patient current = firstPatient;
  79. while (current != null) {
  80. patientCount++;
  81. current = current.getNext();
  82. }
  83. System.out.println();
  84. }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement