You are on page 1of 5

P6.1: Hospital D n ny gip Sinh vin Hiu c gi v phm vi truy cp. /* * Doctor.

java * * This class is used store details about a doctor. * * Copyright 2009 - http://ljbe-course.googlecode.com */ package hospital; import java.util.Scanner; public class Doctor { /** Instance variable to store unique doctor code. */ int code; /** Instance variable to store doctor name. */ String name; /** Instance variable to store the address of the doctor. */ String address; /** Instance variable to store phone number of the doctor. */ String phone; /** Creates a new instance of Doctor */ public Doctor() { code = 0; name = ""; address = ""; phone = ""; } /** * Method to display the doctor information. */ void getDoctorInfo() { System.out.println("The details about the doctor are:"); System.out.println("Code: " + code); System.out.println("Address: " + address); System.out.println("Phone Number: " + phone);

} /** * Method to accept the details about a doctor. */ void setDoctorInfo() { Scanner input = new Scanner(System.in); // Use the Enter key (new line character) as the delimiter input.useDelimiter("\n"); System.out.println("Enter System.out.println("Enter code = input.nextInt(); System.out.println("Enter name = input.next(); System.out.println("Enter address = input.next(); System.out.println("Enter phone = input.next(); } } /* * Patient.java * * This class is used store details about a patient. * * Copyright 2009 - http://ljbe-course.googlecode.com */ package hospital; import java.util.*; public class Patient { /** * Instance variable to store unique patient code. */ int code; /** * Instance variable to store name of the patient. */ String name; details about the doctor:"); doctor's code:"); name:"); address:"); phone number:");

/** * Instance variable to store age of the patient. */ int age; /** * Instance variable to store address of the patient. */ String address; /** * Instance variable to store illness symptoms. */ String symptoms; /** * Instance variable to store code of the * doctor assigned to the patient. */ int doctorCode; /** * Instance variable to store name of the * doctor assigned to the patient. */ String doctorName; /** * Class variable to store the percentage of discount. */ /** * Creates a new instance of Patient. */ public Patient() { code = 0; name = ""; address = ""; doctorCode = 0; doctorName = ""; } /** * Method to display the details of Patient.

*/ void getPatientDetails() { System.out.println("The details about the patient are:"); System.out.println("Code: " + code); System.out.println("Age: " + age); System.out.println("Address: " + address); System.out.println("Symptoms: " + symptoms); } /** * Method to accept the details of Patient. */ void setPatientDetails() { Scanner input = new Scanner(System.in); input.useDelimiter("\n"); System.out.println("Enter System.out.println("Enter code = input.nextInt(); System.out.println("Enter name = input.next(); System.out.println("Enter age = input.nextInt(); System.out.println("Enter address = input.next(); details about the patient:"); patient code:" ); name:"); age:" ); address:");

System.out.println("Enter Symptoms: You can type as many lines as " + "you wish. Enter 0 to stop."); // Accept the details about various symptoms until the user types a zero symptoms = new Scanner(System.in).useDelimiter("0").next(); } } /* * Admin.java * * This program is designed to demonstrate the use of classes Doctor and Patient * defined in the same package. * * Copyright 2009 - http://ljbe-course.googlecode.com */ package info; import hospital.Patient; import hospital.Doctor;

public class Admin { /** * This is the entry point of the application. * @param args the command line arguments */ public static void main(String[] args) { // Create a new Doctor Doctor objDoctor = new Doctor(); // Accept details about the doctor objDoctor.setDoctorInfo(); // Create a new Patient Patient objPatient = new Patient(); // Accept patient details objPatient.setPatientDetails(); // Assign a doctor to a patient objPatient.doctorCode = objDoctor.code; objPatient.doctorName = objDoctor.name; System.out.format("The doctor for %s is %s.", objPatient.name, objDoctor.name); System.out.println(); // Display the patient and doctor details objPatient.getPatientDetails(); objDoctor.getDoctorInfo(); } }

You might also like