Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package hospital;
- public class Hospital {
- public String name, message;
- public int days;
- public final double PRIVATE = 550, SEMI = 350, WARD = 105, PHONE = 4.50, TV = 7.5, MEDS = 275;
- public char room;
- public double room_charges, meds, phone, tv;
- public static double total_amount;
- public String getName(){
- return name;
- }
- public int getDays(){
- return days;
- }
- public static double getTotalAmount(){
- return total_amount;
- }
- Hospital(String theName, int NumDays, char ch){
- name = theName;
- days = NumDays;
- room = ch;
- }
- String getRoom(){
- return message;
- }
- void calculateCharges(){
- switch(room){
- case 'P': case'p':
- message = "Private Room";
- room_charges = PRIVATE * days;
- phone = PHONE;
- tv = TV;
- meds = MEDS * 2;
- total_amount = PRIVATE*days + MEDS*2 + TV + PHONE;
- break;
- case'S': case's':
- message = "Semi-Private Room";
- room_charges = SEMI * days;
- tv = TV;
- meds = MEDS;
- total_amount = SEMI*days + MEDS +TV;
- break;
- case 'W': case'w':
- message = "Ward Room";
- room_charges = WARD * days;
- meds = MEDS /2;
- total_amount = WARD*days + MEDS/2;
- break;
- }
- }
- }
- package hospital;
- import java.text.NumberFormat;
- public class TestHospital {
- public static void main(String[] args) {
- NumberFormat f = NumberFormat.getCurrencyInstance();
- Hospital ch = new Hospital("John Harris", 5, 'P');
- System.out.println("\tThe ValPar Community Hospital");
- System.out.println("\tPatient Billing Statement\n");
- System.out.println("Patient: \t\t" + ch.getName());
- System.out.println("Number of days:\t\t" + ch.getDays());
- ch.calculateCharges();
- System.out.println("\nType of Room:\t\t" + ch.getRoom());
- System.out.println("Room charge: \t\t" + f.format(ch.room_charges));
- System.out.println("Telephone: \t\t" + f.format(ch.phone));
- System.out.println("Television: \t\t" + f.format(ch.tv));
- System.out.println("Medication: \t\t" + f.format(ch.meds));
- System.out.println("Total amount due \t" + f.format(ch.getTotalAmount()));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement