Untitled
unknown
plain_text
a year ago
3.0 kB
3
Indexable
import java.util.Date; class Inpatient { private static int hospitalNumberCounter = 1000; private String name; private int age; private int hospitalNumber; private Date dateOfAdmission; private double roomRent; // Default constructor public Inpatient() { this.hospitalNumber = generateHospitalNumber(); } // Copy constructor public Inpatient(Inpatient other) { this.name = other.name; this.age = other.age; this.hospitalNumber = generateHospitalNumber(); this.dateOfAdmission = other.dateOfAdmission; this.roomRent = other.roomRent; } // Parameterized constructor public Inpatient(String name, int age, Date dateOfAdmission, double roomRent) { this.name = name; this.age = age; this.hospitalNumber = generateHospitalNumber(); this.dateOfAdmission = dateOfAdmission; this.roomRent = roomRent; } private static int generateHospitalNumber() { return hospitalNumberCounter++; } // Methods for input, display, and checking admission date public void inputRecord(String name, int age, Date dateOfAdmission, double roomRent) { this.name = name; this.age = age; this.dateOfAdmission = dateOfAdmission; this.roomRent = roomRent; } public void displayRecord() { System.out.println("Name: " + name); System.out.println("Age: " + age); System.out.println("Hospital Number: " + hospitalNumber); System.out.println("Date of Admission: " + dateOfAdmission); System.out.println("Room Rent: " + roomRent); System.out.println(); } public boolean isAdmittedToday() { // Implementation to check if the date of admission is today's date // (You may need to compare with the current date) return false; // Placeholder, actual implementation needed } } public class Main { public static void main(String[] args) { // Part a) Testing constructors Inpatient patient1 = new Inpatient(); Inpatient patient2 = new Inpatient(patient1); Inpatient patient3 = new Inpatient("John Doe", 25, new Date(), 150.0); // Part d) Testing methods patient1.displayRecord(); patient3.inputRecord("Jane Smith", 30, new Date(), 200.0); patient3.displayRecord(); // Part e) Creating an array of inpatient records Inpatient[] inpatientRecords = new Inpatient[3]; inpatientRecords[0] = new Inpatient("Alice Johnson", 40, new Date(), 180.0); inpatientRecords[1] = new Inpatient("Bob Miller", 55, new Date(), 220.0); inpatientRecords[2] = new Inpatient("Eva Brown", 28, new Date(), 170.0); for (Inpatient record : inpatientRecords) { record.displayRecord(); } // Part f) Checking for duplicate records and patients admitted today // Implementation needed } }
Editor is loading...
Leave a Comment