Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
3.1 kB
7
Indexable
Never
import java.util.Scanner;

class Patient {
    private String name;
    private int age;
    private String hospitalNumber;

    public void input() {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter name: ");
        name = scanner.nextLine();
        System.out.print("Enter age: ");
        age = scanner.nextInt();
        scanner.nextLine(); // Consume newline
        System.out.print("Enter hospital number: ");
        hospitalNumber = scanner.nextLine();
    }

    public void display() {
        System.out.println("Name: " + name);
        System.out.println("Age: " + age);
        System.out.println("Hospital Number: " + hospitalNumber);
    }
}

class Inpatient extends Patient {
    private String departmentName;
    private String admissionDate;
    private String roomType;

    public void input() {
        super.input();
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter department name: ");
        departmentName = scanner.nextLine();
        System.out.print("Enter admission date: ");
        admissionDate = scanner.nextLine();
        System.out.print("Enter room type (Special/SemiSpecial/General): ");
        roomType = scanner.nextLine();
    }

    public void display() {
        super.display();
        System.out.println("Department Name: " + departmentName);
        System.out.println("Admission Date: " + admissionDate);
        System.out.println("Room Type: " + roomType);
    }

    public String getRoomType() {
        return roomType;
    }
}

class Billing extends Inpatient {
    private String dischargeDate;

    public void input() {
        super.input();
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter discharge date: ");
        dischargeDate = scanner.nextLine();
    }

    public void displayTotalAmount() {
        double consultancyChargesPerDay;
        double roomRentPerDay;

        switch (getRoomType()) {
            case "Special":
                consultancyChargesPerDay = 1000.00;
                roomRentPerDay = 200.00;
                break;
            case "SemiSpecial":
                consultancyChargesPerDay = 500.00;
                roomRentPerDay = 100.00;
                break;
            case "General":
                consultancyChargesPerDay = 100.00;
                roomRentPerDay = 50.00;
                break;
            default:
                consultancyChargesPerDay = 0.00;
                roomRentPerDay = 0.00;
                break;
        }

        // Assuming a fixed number of days for demonstration purposes
        int daysStayed = 5;
        double totalConsultancyCharges = consultancyChargesPerDay * daysStayed;
        double totalRoomRent = roomRentPerDay * daysStayed;

        double totalAmount = totalConsultancyCharges + totalRoomRent;
        System.out.println("Total Amount: Rs. " + totalAmount);
    }
}

public class Main {
    public static void main(String[] args) {
        Billing billing = new Billing();
        billing.input();
        billing.display();
        billing.displayTotalAmount();
    }
}
Leave a Comment