Java

You might also like

You are on page 1of 7

enum Availability {

// TASK 1(i): enum constant values and fields come here [6 marks]
// Complete the enum declaration in Availability class using the data stated in
Table 1

M("Morning",8.00d,12.00d),
A("Afternoon",13.00d,18.00d),
N("Night",19.00d,23.00d);

private String session;


private double starthour;
private double endhour;

Availability(String s, double start, double end) {


session = s;
starthour = start;
endhour = end;
}

public String getSession() {


return session;
}

public double getStartTime() {


return starthour;
}

public double getEndTime() {


return endhour;
}

public class Doctor {


private String name;
private double consultationFee;
private String specialization;
private String roomNum;
Availability time;

public Doctor(String name, double consultationFee, String specialization,


String roomNum, String t) {
this.name=name;
this.consultationFee = consultationFee;
this.specialization = specialization;
this.roomNum = roomNum;
time = Enum.valueOf(Availability.class, t);
}

public double getConsultationFee() {


return consultationFee;
}

public String getSpecial() {


return specialization;
}

public String getroomNum() {


return roomNum;
}

public void displayDoctor() {


System.out.println("Name :" + name);
System.out.println("Specialized in: " + specialization);
System.out.println("Room Number: " + roomNum);

// TASK 2(i): Modify if..else statement below to display starthour and endhour for
every session. [6 marks]

if ((time.session="Morning")) {

System.out.println("Time available from " + starthour + " to " +


endhour);

} else if ((time.session.equals="Afternoon")) {

System.out.println("Time available from " + starthour + " to " +


endhour());

} else if ((time.session.equals="Night")) {

System.out.println("Time available from " + starthour + " to " +


endhour());

}
}

import java.util.ArrayList;

public class Patient {


private String name;
private String phoneNum;
private String address;
private int age;
private Consultation cons;
private Doctor doctor;
ArrayList<Medication> medicItem = new ArrayList<Medication>();
public double OLD_CITIZEN=0.10;

Patient(String name, String phoneNum, String address, int age, Consultation


app) {
this.name=name;
this.phoneNum=phoneNum;
this.address = address;
this.age = age;
cons = app;

}
public String getName() {
return name;
}

public String getPhoneNumber() {


return phoneNum;
}

public String getAddress() {


return address;
}
public int getAge() {
return age;
}

// TASK 3(i): Define buyMedication method to establish association relationship


between class Patient and Medication. [4 marks]
// TASK 3(ii): Medication objects passed to this method can be added to the
ArrayList.
public void buyMedication(){
Patient p = new Medication();
medicItem=p;

public void consultSet(Consultation app) {


cons = app;
}

public void meetDr(Doctor d) {


doctor = d;
}

public void consultDisplay() {

doctor.display();

// TASK 4(i): Modify the codes in method consultDisplay to display consultation


date and time. [2 marks]

System.out.println("\nConsultation date: " + cons.date);


System.out.printf("Consultation time : %.2f", cons.time);
}

public void display() {


double totalprice=0;
double payableCost = 0;
System.out.println("Name :" + name);
System.out.println("Phone Number: " + phoneNum);
System.out.println("Address: " + address);
System.out.println("List of medication :");
System.out.println();

// TASK 5(i): Modify the following codes to display the medication list, calculate
and display the medicine total price, consultation fee and total cost (medicine +
consultation fee) [10 marks]

for (int i = 0; i < medicItem.size(); i++) {


System.out.println("[" + (i + 1) + "]Item: " + medication + "\n
Description :"+ description);
System.out.printf("Price : Rm%.2f\n", price);
totalprice += price * qty;
System.out.println();
}

payableCost=totalprice + consultationFee;
System.out.printf("MEDICINE : RM%.2f\n",totalprice );
System.out.printf("CONSULTATION FEE : RM%.2f\n",consultationFee() );
System.out.printf("TOTAL : RM%.2f\n",payableCost );

if (age>=65)
{
double totalDiscount=payableCost*OLD_CITIZEN;
payableCost=payableCost-totalDiscount;
System.out.printf("TOTAL AFTER OLD CITIZEN DISCOUNT : RM%.2f\
n",payableCost );
}

}
}

import java.util.ArrayList;
import java.util.Scanner;

public class ClinicApp {


public static void main(String[] args) {

// TASK 6(i): Modify the array of object implementation below to ArrayList - [6


marks]
// TASK 6(i): Use the ArrayList medication to store all Medication objects.
// TASK 6(i): Use the ArrayList doctorList to store all the Doctor objects.

ArrayList<Medication> medication = new ArrayList<Medication>();


ArrayList<Doctor> doctorList = new ArrayList<Doctor>();
Scanner input = new Scanner(System.in);
int choice, medicNum;

Medication m1 = new Medication("Aspirin tablet", "Reduce blood


clotting\t", 20.00, "1");
Medication m2 = new Medication("Allergy shots", "\tImprove immune
system\t", 150.50, "2");
Medication m3 = new Medication("Antihistamines", "Reduce blood
clotting\t", 40.80, "3");
Medication m4 = new Medication("Nasal sprays", "\tEase nasal
congestion\t", 70.00, "4");
Medication m5 = new Medication("Calamine lotion", "Relieve itchy skin\
t", 25.50, "5");

Doctor dr1 = new Doctor("Dr. Arif Izzuddin, M.D, M.S.", 30.0,


"Dermatologists", "A-115","N");
Doctor dr2 = new Doctor("Dr. Hafiz Hakim, M.D", 25.00, "Infectious
diseases", "C-311", "M");
Doctor dr3 = new Doctor("Dr. Nuha Faqihah, M.D, M.S", 40.00,
"Paediatrician", "B-214","A");

medication.add(m1);
medication.add(m2);
medication.add(m3);
medication.add(m4);
medication.add(m5);

doctorlist.add(dr1);
doctorlist.add(dr2);
doctorlist.add(dr3);

// End of TASK 6

String name;
String hp;
String add;
String date = "";
double time = 0.0;
int age=0;

System.out.println("******** KLINIK MESRA ********");


System.out.print("Enter patient name: ");
name = input.nextLine();

System.out.print("Enter patient address : ");


add = input.nextLine();

System.out.print("Enter patient phone number: ");


hp = input.nextLine();

System.out.print("Enter patient phone age: ");


age = input.nextInt();

Consultation app = new Consultation(date, time);

Patient pt = new Patient(name, add, hp,age, app);

do {
System.out.println("\n******** KLINIK MESRA ********");
System.out.println("1. Consultation Detail");
System.out.println("2. Medication Details");
System.out.println("3. Payment Detail");
System.out.println("4. Exit");

System.out.print("\nPlease enter your choice (1-4) : ");


choice = input.nextInt();
System.out.println();

switch (choice) {
case 1:
System.out.println("******** Consultation
Detail ********");
System.out.println();
System.out.print("Enter date (dd/mm/yy): ");
date = input.next();
System.out.print("Enter time (24hour
format):");
time = input.nextDouble();
System.out.println();
app = new Consultation(date, time);
pt = new Patient(name, add, hp,age,app);

int pick;
System.out.println("Doctor Detail:");
System.out.println();

// TASK 7(i): Complete the body of 'if statements' below to invoke method display
info based on Doctor's availability, invoke methods meetDr() and consutSet() once
the condition is met. [6 marks]

if (time > 8.00 && time <= 12.00) {

//TASK 7(i): methods invocation come here


displayDoctor();
meetDr();
consultSet();

} else if (time > 12.00 && time <= 18.00) {

//TASK 7(i): methods invocation come here


displayDoctor();
meetDr();
consultSet();

} else if (time > 18.00 && time <= 23.00) {

//TASK 7(i): methods invocation come here


displayDoctor();
meetDr();
consultSet();

break;

case 2:
System.out.println("LIST OF MEDICATION
");
System.out.println("Medication\t\t\t\
tDescription\t\t\tPrice(RM)");

for (int i = 0; i < medication.size(); i++) {


Medication m = medication.get(i);
System.out.println((i + 1) + "." +
m.getMedic() + "\t\t" + m.getDescription() + "\t\t" + m.getPrice());
}

String buy;
int qty=0;
System.out.print("\n How many type of
medicine?: ");
medicNum = input.nextInt();

for (int i = 0; i < medicNum; i++) {


System.out.println("");
System.out.print("Enter medicine
id: ");
buy = input.next();
System.out.print("Enter quantity:
");
qty = input.nextInt();

for (Medication medic : medication)


{

if
(medic.getID().equals(buy)) {

pt.buyMedication(medic);
medic.setQty(qty);

System.out.println("Item : " + medic.getMedic()+ "\t\t Quantity : "+qty);


}
}
}

break;

case 3:
System.out.println("<<<< PAYMENT DETAIL
>>>>\n");
pt.display();
break;

default:
System.out.println("Thank you for
using our system");
break;
}

} while (choice != 4);


}
}

You might also like