UML STATE MODEL ( STATECHART DIAGRAM ) AND JAVA

A state diagram is a type of diagram used in computer science and related fields to describe the behavior of systems. State diagrams require that the system described is composed of a finite number of states; sometimes, this is indeed the case, while at other times this is a reasonable abstraction. Many forms of state diagrams exist, which differ slightly and have different semantics.

Here is the UML State Model for Hospital Management System implemented in Java.
UML State Model (StateChart) for Hospital Management System
State.java
package SMD3;

public enum State {
  ILL,CURE,APPOINTMENT,DIAGNOSE,CONSULT,MEDICINES
}

Patient.java
package SMD3;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Patient {
 
 private String name;
 private State state;
 
 public void Appointment(){
  Boolean ill=true;
  
  
  setState(State.ILL);
  System.out.println("The Patient is: "+State.ILL);
  System.out.println("Press any Key:");
  try{
   BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
   String str = r.readLine();
  }catch(Exception e){}
  if(ill){
   setState(State.APPOINTMENT);
   System.out.println("The Patient is :  "+State.APPOINTMENT);
  }
  
  }

 public void Consult(){
  try{
   BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
   String str = r.readLine();
  }catch(Exception e){}
  Boolean ill=true;
  if(ill){
  setState(State.CONSULT);
  System.out.println("The Patent is : "+State.CONSULT);
  }
  }
 
 public void Diagnose(){
  try{
   BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
   String str = r.readLine();
  }catch(Exception e){}
  Boolean ill=true;
  if(ill){
   setState(State.DIAGNOSE);
   System.out.println("Patient is under:  "+State.DIAGNOSE);
   setState(State.MEDICINES);
   System.out.println("Patient is give: "+State.MEDICINES);
  }
  
  
 }
 
 public void Illness(){
  Boolean ill=false;
  try{
   BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
   String str = r.readLine();
  }catch(Exception e){}
  if(ill==false){
   setState(State.CURE);
   System.out.println("The Patient is:  "+State.CURE);
  }else{
   setState(State.ILL);
   System.out.println("The Patient is:  "+State.ILL);
   Diagnose();
  }
 }
test.java
package SMD3;

public class test {

 public static void main(String[] args) {
  Patient patient = new Patient();
  patient.Appointment();
  patient.Consult();
  patient.Diagnose();
  patient.Illness();
 }
}

Comments