
Please check the errors,if any,in this code...i am a java beginner
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Hospital
{
/**
* @param args
*/
public static void main(String[] args)
{
// TODO Auto-generated method stub
Map<Integer,Patient> patients=new HashMap<Integer,Patient>();
PatientFunction pf=new PatientFunction();
Patient p1=new Patient();
Calendar c=Calendar.getInstance();
Date d=new Date();
d.setMonth(d.getMonth()-1);
c.setTime(d);
p1.setAge(25);
p1.setName("Arg");
p1.setLastAppointment(c);
patients.put(p1.getPatientId(), p1);
Scanner s=new Scanner(System.in);
int ctr=0;
do
{
System.out.println("::::::::Hospital::::::::");
System.out.println("Enter 1.Add a patient 2.Update Patient 3.Search patient 4.Display patients or View status");
ctr=s.nextInt();
s.nextLine();
switch(ctr)
{
case 1:
Patient p=pf.addPatient();
if(p==null)
System.out.println("Incorrect input");
else
patients.put(p.getPatientId(), p);
break;
case 2:
System.out.println("Enter a patient ID");
int pid=s.nextInt();
s.nextLine();
if(patients.containsKey(pid))
{
Patient p2=pf.updatePatient(patients.get(pid));
if(p2!=null)
patients.put(p2.getPatientId(), p2);
else
System.out.println("Invalid input");
}
else
{
System.out.println("Patient with the ID does not exist");
}
break;
case 3:
System.out.println("Enter a patient ID");
pid=s.nextInt();
s.nextLine();
if(patients.containsKey(pid))
{
pf.displayPatientDetails(patients.get(pid));
}
else
{
System.out.println("Patient with the ID does not exist");
}
break;
case 4:
if(patients.size()==0)
System.out.println("No patients in list");
else
{
ArrayList<Patient> al=new ArrayList<Patient>(patients.values());
pf.displayAll(al);
}
break;
}
System.out.println("Continue? Enter y or n");
if(s.nextLine().toLowerCase().equals("y"))
ctr=999;
}
while(ctr==999);
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.