Quote
Problem Description:
Using the Linked List and Queue concept, develop a
reservation system for Clinic Ruslan,
whereby the system should be able to:
-Delete the reservation
-Add the reservation
-View the current reservation
-Insert new reservation(priority case)
Do you want to continue?
Choose Option
Add
Delete
View
Exit
Due Date: 07 July 2011
Using the Linked List and Queue concept, develop a
reservation system for Clinic Ruslan,
whereby the system should be able to:
-Delete the reservation
-Add the reservation
-View the current reservation
-Insert new reservation(priority case)
Do you want to continue?
Choose Option
Add
Delete
View
Exit
Due Date: 07 July 2011
Current Coding
//In the name of Allah
/* Problem Description:
Using the Linked List and Queue concept, develop a
reservation system for Clinic Ruslan,
whereby the system should be able to:
-Delete the reservation
-Add the reservation
-View the current reservation
-Insert new reservation(priority case)
Do you want to continue?
Choose Option
Add
Delete
View
Exit
Due Date: 07 July 2011
*/
/*==Class ClinicRuslan=============================================================*/
import javax.swing.*; //JOP and JFrame
import java.util.*;
class ClinicRuslan{
public static void main(String [] args){
/*==Variable Declaration, Object Constructs=============================================================*/
String name="";
String IC=""; //MYKad No
String contactNo=""; //Use string to get zero at the front e.g. 0134567890
String address="";
String gender="";
int age=0;
//String date=""; //reservation date
double time=0.0; //reservation time
String priority=""; //normal or critical
//
int choice = 0;
String option = "";
String output = "";
//Setting Queue
Queue normalQueue = new Queue();
Queue priorityQueue = new Queue();;
Patient temp;
LinkedList AllQueue = new LinkedList();/*
AllQueue.add(normalQueue);
AllQueue.add(priorityQueue);*/
/*==MAIN CONTENT=============================================================*/
while (choice==0){
option=JOptionPane.showInputDialog(null,"Choose Option\n\tAdd\n\tDelete\n\tView\n\tExit");
/*==Add=============================================================*/
if (option.equalsIgnoreCase("Add"))
{
//JOptionPane.showMessageDialog(null,"ADDING");
name=JOptionPane.showInputDialog(null,"Name");
IC=JOptionPane.showInputDialog(null,"IC");
contactNo=JOptionPane.showInputDialog(null,"Contact No");
address=JOptionPane.showInputDialog(null,"Address");
gender=JOptionPane.showInputDialog(null,"Gender[Male/Female]");
age=Integer.parseInt(JOptionPane.showInputDialog(null,"Age"));
time=Double.parseDouble(JOptionPane.showInputDialog(null,"Time[24hours system]"));
priority=JOptionPane.showInputDialog(null,"Priority[normal/critical]");
temp = new Patient(name,IC,contactNo,address,gender,age,time,priority);
if (temp.priorityCheck())
{
priorityQueue.enqueue(temp); //Queue for Critical Priority Condition
}
else
{
normalQueue.enqueue(temp); //Queue for Normal Patients
}
}
/*==Delete=============================================================*/
else if (option.equalsIgnoreCase("Delete"))
{
//View First
if(!priorityQueue.isEmpty())
{
for(int i=0; i<priorityQueue.size(); i++)
{
temp = (Patient) priorityQueue.front();
//System.out.println(temp.toString());
output+=temp.toString();
}
}
if(!normalQueue.isEmpty())
{
for(int i=0; i<normalQueue.size(); i++)
{
temp = (Patient) normalQueue.front();
//System.out.println(temp.toString());
output+=temp.toString();
}
}
JOptionPane.showMessageDialog(null,"Select which patient?(Define the name.)\n"+output);
output="";
}
/*==View=============================================================*/
else if (option.equalsIgnoreCase("View"))
{
/*for(int i=0; i<AllQueue.size(); i++)
{
temp = (Patient) AllQueue.get(i);
System.out.println(temp.toString());
}*/
if(!priorityQueue.isEmpty())
{
for(int i=0; i<priorityQueue.size(); i++)
{
temp = (Patient) priorityQueue.front();
//System.out.println(temp.toString());
output+=temp.toString();
}
}
if(!normalQueue.isEmpty())
{
for(int i=0; i<normalQueue.size(); i++)
{
temp = (Patient) normalQueue.front();
//System.out.println(temp.toString());
output+=temp.toString();
}
}
JOptionPane.showMessageDialog(null,"VIEWING\n"+output);
output="";
}
/*==Exit=============================================================*/
else if (option.equalsIgnoreCase("Exit"))
break;
/*==Error Input Notification=============================================================*/
else
JOptionPane.showMessageDialog(new JFrame(), "You have entered invalid input. Please enter \"Add\", \"Delete\", \"View\", or \"Exit\" ", "Wrong Input",JOptionPane.ERROR_MESSAGE);
/*==Choose to continue or not=============================================================*/
choice=JOptionPane.showConfirmDialog(null,"Do you want to continue?","Continue?", JOptionPane.YES_NO_OPTION);//return 0 for yes option.
}
/*==END MAIN CONTENT=============================================================*/
System.exit(0);
}
}
/*==Class Queue=============================================================*/
class Queue {
protected LinkedList list;
public Queue() {
list = new LinkedList();
} //default constructor
public boolean isEmpty() {
return list.isEmpty();
}//method isEmpty
public int size() {
return list.size();
}// method size
public void enqueue(Object element) {
list.addLast(element);
} //method enqueue
public Object dequeue() {
return list.removeFirst();
} //method dequeue
public Object front() {
return list.getFirst();
} //method front
public Object rear(){
return list.getLast();
}
} // Queue class
//class Patient
class Patient{
protected String name;
protected String IC; //MYKad No
protected String contactNo;
protected String address;
protected String gender;
protected int age;
//protected String date; //reservation date
protected double time; //reservation time
protected String priority; //normal or critical
//Patient(String a,String b,int c,String d,String e,int f,String g,double h,String i){
Patient(String a,String b,String c,String d,String e,int f,double h,String i){
name=a;
IC=b;
contactNo=c;
address=d;
gender=e;
age=f;
//date=g;
time=h;
priority=i;
}
public String getName(){return name;}
public String getIC(){return IC;}
public String getContact(){return contactNo;}
public String getAddress(){return address;}
public String getGender(){return gender;}
public int getAge(){return age;}
//public String getDate(){return date;}
public double getTime(){return time;}
public String getPriority(){return priority;}
public boolean priorityCheck(){
if (getPriority().equalsIgnoreCase("critical"))
return true;
else
return false;
}
public String toString(){
return "Name: " + getName() + ", IC No: " + getIC() + ", Contact no : " + getContact() + ", Address : " + getAddress() + ", Gender : "
+ getGender() + ", Age : " + getAge() + ", Time : " + getTime() + ", Condition : " + getPriority() + "\n";
}
}

New Topic/Question
Reply




MultiQuote





|