Advertisement
Guest User

Untitled

a guest
Jun 30th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. package hospital;
  2.  
  3. public class Hospital {
  4. public String name, message;
  5. public int days;
  6. public final double PRIVATE = 550, SEMI = 350, WARD = 105, PHONE = 4.50, TV = 7.5, MEDS = 275;
  7. public char room;
  8. public double room_charges, meds, phone, tv;
  9.  
  10. public static double total_amount;
  11.  
  12. public String getName(){
  13. return name;
  14. }
  15.  
  16. public int getDays(){
  17. return days;
  18. }
  19.  
  20. public static double getTotalAmount(){
  21. return total_amount;
  22. }
  23.  
  24. Hospital(String theName, int NumDays, char ch){
  25. name = theName;
  26. days = NumDays;
  27. room = ch;
  28. }
  29.  
  30. String getRoom(){
  31. return message;
  32. }
  33.  
  34. void calculateCharges(){
  35. switch(room){
  36. case 'P': case'p':
  37. message = "Private Room";
  38. room_charges = PRIVATE * days;
  39. phone = PHONE;
  40. tv = TV;
  41. meds = MEDS * 2;
  42. total_amount = PRIVATE*days + MEDS*2 + TV + PHONE;
  43.  
  44. break;
  45.  
  46. case'S': case's':
  47. message = "Semi-Private Room";
  48. room_charges = SEMI * days;
  49. tv = TV;
  50. meds = MEDS;
  51. total_amount = SEMI*days + MEDS +TV;
  52.  
  53. break;
  54.  
  55. case 'W': case'w':
  56. message = "Ward Room";
  57. room_charges = WARD * days;
  58. meds = MEDS /2;
  59. total_amount = WARD*days + MEDS/2;
  60.  
  61. break;
  62. }
  63. }
  64. }
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72. package hospital;
  73.  
  74. import java.text.NumberFormat;
  75.  
  76. public class TestHospital {
  77.  
  78. public static void main(String[] args) {
  79. NumberFormat f = NumberFormat.getCurrencyInstance();
  80.  
  81. Hospital ch = new Hospital("John Harris", 5, 'P');
  82.  
  83. System.out.println("\tThe ValPar Community Hospital");
  84. System.out.println("\tPatient Billing Statement\n");
  85.  
  86. System.out.println("Patient: \t\t" + ch.getName());
  87. System.out.println("Number of days:\t\t" + ch.getDays());
  88.  
  89. ch.calculateCharges();
  90. System.out.println("\nType of Room:\t\t" + ch.getRoom());
  91. System.out.println("Room charge: \t\t" + f.format(ch.room_charges));
  92. System.out.println("Telephone: \t\t" + f.format(ch.phone));
  93. System.out.println("Television: \t\t" + f.format(ch.tv));
  94. System.out.println("Medication: \t\t" + f.format(ch.meds));
  95. System.out.println("Total amount due \t" + f.format(ch.getTotalAmount()));
  96.  
  97. }
  98.  
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement