4ое задание

mail@pastecode.io avatar
unknown
java
a year ago
2.5 kB
1
Indexable
Never
import java.util.Scanner;

public class Hospital {
    private int totalPatients;
    private int dischargedPatients;
    private int remainingPatients;
    private double averageStayDuration;

    public Hospital(int totalPatients, int dischargedPatients, int remainingPatients, double averageStayDuration) {
        this.totalPatients = totalPatients;
        this.dischargedPatients = dischargedPatients;
        this.remainingPatients = remainingPatients;
        this.averageStayDuration = averageStayDuration;
    }

    public int getTotalPatients() {
        return totalPatients;
    }

    public int getDischargedPatients() {
        return dischargedPatients;
    }

    public int getRemainingPatients() {
        return remainingPatients;
    }

    public double getAverageStayDuration() {
        return averageStayDuration;
    }

    public void setTotalPatients(int totalPatients) {
        this.totalPatients = totalPatients;
    }

    public void setDischargedPatients(int dischargedPatients) {
        this.dischargedPatients = dischargedPatients;
    }

    public void setRemainingPatients(int remainingPatients) {
        this.remainingPatients = remainingPatients;
    }

    public void setAverageStayDuration(double averageStayDuration) {
        this.averageStayDuration = averageStayDuration;
    }

    public void calculateRemainingPatients() {
        remainingPatients = totalPatients - dischargedPatients;
    }

    public void calculateAverageStayDuration() {
        averageStayDuration = (double) dischargedPatients / totalPatients;
    }

    public String getReport() {
        return "Total Patients: " + totalPatients +
                "\nDischarged Patients: " + dischargedPatients +
                "\nRemaining Patients: " + remainingPatients +
                "\nAverage Stay Duration: " + averageStayDuration;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.print("Enter the total number of patients: ");
        int totalPatients = scanner.nextInt();

        System.out.print("Enter the number of discharged patients: ");
        int dischargedPatients = scanner.nextInt();

        Hospital hospital = new Hospital(totalPatients, dischargedPatients, 0, 0.0);

        hospital.calculateRemainingPatients();
        hospital.calculateAverageStayDuration();

        System.out.println(hospital.getReport());
    }
}