好的,所以我必须在医院管理系统上制作一个程序,我必须记录病人,医生,预约..现在我已经让病人和医生记录使用物体和arraylist但我在分配特定的问题时遇到了问题根据病人的病情向病人求医..这就是我基本上做的事情: -
Appointment app1= new Appointment();
Patient ap2= new Patient();
Doctor ii2= new Doctor();
for(i=0;i<appointments.size();i++){
app1=appointments.get(i);
ap2=patient.get(i);
ii2=doctor.get(i);
if(ap2.getIllness()==1){
if(ii2.getDocspecialization()==1){
System.out.println("the patient "+ap2.getId()+" is appointed to "+ii2.getDocname());
System.out.println("Appointment of patient"+ap2.getId());
System.out.println(app1.toString());
}
}
if(ap2.getIllness()==2){
if(ii2.getDocspecialization()==2){
System.out.println("the patient "+ap2.getId()+" is appointed to "+ii2.getDocname());
System.out.println("Appointment of patient"+ap2.getId());
System.out.println(app1.toString());
}
}
if(ap2.getIllness()==3){
if(ii2.getDocspecialization()==3){
System.out.println("the patient "+ap2.getId()+" is appointed to "+ii2.getDocname());
System.out.println("Appointment of patient"+ap2.getId());
System.out.println(app1.toString());
}
}
if(ap2.getIllness()==4){
if(ii2.getDocspecialization()==4){
System.out.println("the patient "+ap2.getId()+" is appointed to "+ii2.getDocname());
System.out.println("Appointment of patient"+ap2.getId());
System.out.println(app1.toString());
}
}
if(ap2.getIllness()==5){
if(ii2.getDocspecialization()==5){
System.out.println("the patient "+ap2.getId()+" is appointed to "+ii2.getDocname());
System.out.println("Appointment of patient"+ap2.getId());
System.out.println(app1.toString());
}
}
if(ap2.getIllness()==6){
if(ii2.getDocspecialization()==6){
System.out.println("the patient "+ap2.getId()+" is appointed to "+ii2.getDocname());
System.out.println("Appointment of patient"+ap2.getId());
System.out.println(app1.toString());
}
}
}
我在这里犯的错误是什么?我有一份患者可以选择的疾病清单,这就是为什么我使用getillness()== 1同样适用于医生.. 为了以防万一,我将展示我的整个计划......
import java.util.ArrayList;
import java.util.Scanner;
public class patientdoctor {
public static void main(String[] args) {
int id,num;
int docid,docnum;
Scanner src= new Scanner(System.in);
Scanner sc= new Scanner(System.in);
Scanner ti= new Scanner(System.in);
Scanner pick= new Scanner(System.in);
Scanner newid= new Scanner(System.in);
Scanner newname= new Scanner(System.in);
Scanner newnum= new Scanner(System.in);
Scanner special= new Scanner(System.in);
int i,it,illness;
int doci,docit,docspecialization;
int pick1;
String name,docname;
String illname;
ArrayList<Patient> patient= new ArrayList<Patient>();
ArrayList<Doctor> doctor= new ArrayList<Doctor>();
for(i=0;i<=2;i++){
Patient xx = new Patient();
System.out.println("Enter the ID of the patient");
id=src.nextInt();
xx.setId(id);
System.out.println("Enter the name of the patient");
name=ti.next();
xx.setName(name);
System.out.println("Enter the number of the patient");
num=sc.nextInt();
xx.setNum(num);
System.out.println("Enter the illness of the patient");
System.out.println("Type 1 if the patient has some sort of allergy");
System.out.println("Type 2 if the patient has some sort of hearing problems");
System.out.println("Type 3 if the patient has some teeth problems");
System.out.println("Type 4 if the patient has some eye problems");
System.out.println("Type 5 if the patient has some pregnancy problems");
System.out.println("Type 6 if the patient has some heart problems");
Scanner ill= new Scanner(System.in);
illness=ill.nextInt();
xx.setIllness(illness);
if(illness==1){
illname="Allergy";
pick1=1;
xx.setIllname(illname);
}
if(illness==2){
illname="hearing problems";
pick1=2;
xx.setIllname(illname);
}
if(illness==3){
illname="teeth problems";
pick1=3;
xx.setIllname(illname);
}
if(illness==4){
illname="eye problem";
pick1=4;
xx.setIllname(illname);
}
if(illness==5){
illname="pregnancy problems";
pick1=5;
xx.setIllname(illname);
}
if(illness==6){
illname="heart problems";
pick1=6;
xx.setIllname(illname);
}
patient.add(xx);
}
Patient pp= new Patient();
for(i=0;i<patient.size();i++){
pp=patient.get(i);
System.out.println(pp.toString());
}
System.out.println("Enter the id of a patient");
it=sc.nextInt();
Patient tt= new Patient();
for(i=0;i<patient.size();i++)
{
tt=patient.get(i);
if(it==tt.getId())
System.out.println(tt.toString());
}
int id1;
System.out.println("Enter the id of the patient you want to update");
Scanner id11= new Scanner(System.in);
id1=id11.nextInt();
int up,id2;
String namess;
int phones;
Patient dd= new Patient();
for(i=0;i<patient.size();i++){
dd=patient.get(i);
if(id1==dd.getId()){
System.out.println("If you want to change the name, type 2");
System.out.println("If you want to change the number, type 3");
System.out.println("If you want to change the id, type 1");
up=pick.nextInt();
if(up==1){
System.out.println("Enter a new ID ");
Scanner idd= new Scanner(System.in);
id=idd.nextInt();
dd.setId(id);
patient.remove(dd);
patient.add(dd);
break;
}
else if(up==2){
System.out.println("Enter a new name");
Scanner namme=new Scanner(System.in);
namess=namme.next();
dd.setName(namess);
patient.remove(dd);
patient.add(dd);
break;
}
else if(up==3){
System.out.println("Enter a new phone");
Scanner newphone= new Scanner(System.in);
phones=newphone.nextInt();
dd.setNum(phones);
patient.remove(dd);
patient.add(dd);
break;
}
}
}
System.out.println(dd);
System.out.println("-----");
for(i=0;i<patient.size();i++){
pp=patient.get(i);
System.out.println(pp.toString());
}
for(i=0;i<=3;i++){
Doctor xx = new Doctor();
System.out.println("Enter the ID of the Doctor");
docid=src.nextInt();
xx.setDocid(docid);
System.out.println("Enter the name of the Doctor");
docname=ti.next();
xx.setDocname(docname);
System.out.println("Enter the number of the Doctor");
docnum=sc.nextInt();
System.out.println("Enter the Doctor "+xx.getDocname()+" specialization");
System.out.println("Type 1 for Allergist");
System.out.println("Type 2 for Audiologist");
System.out.println("Type 3 for Dentist");
System.out.println("Type 4 for Ophthalmologist");
System.out.println("Type 5 for Obstetrician");
System.out.println("Type 6 for Cardiologist");
Scanner specials= new Scanner(System.in);
docspecialization=specials.nextInt();
xx.setDocspecialization(docspecialization);
xx.setDocnum(docnum);
doctor.add(xx);
}
Doctor ppt= new Doctor();
for(i=0;i<doctor.size();i++){
ppt=doctor.get(i);
System.out.println(ppt.toString());
}
System.out.println("Enter the id of a doctor");
int dit=sc.nextInt();
Doctor tht= new Doctor();
for(i=0;i<doctor.size();i++)
{
tht=doctor.get(i);
if(dit==tht.getDocid())
System.out.println(tht.toString());
}
System.out.println("Enter the ID of the doctor you want to remove from the record");
Doctor qq= new Doctor();
int search;
Scanner removedoc= new Scanner(System.in);
search=removedoc.nextInt();
for(i=0;i<doctor.size();i++)
{
qq=doctor.get(i);
if(search==qq.getDocid()){
doctor.remove(qq);
}
}
Doctor kk= new Doctor();
for(i=0;i<doctor.size();i++){
kk=doctor.get(i);
System.out.println(doctor.get(i));
}
ArrayList<Appointment> appointments= new ArrayList<Appointment>();
int month,year;
int day;
Patient ap= new Patient();
Doctor ii= new Doctor();
for(i=0;i<patient.size();i++){
Appointment app= new Appointment();
ap=patient.get(i);
ii=doctor.get(i);
System.out.println("Enter the year "+ap.getId()+" has an appointment");
Scanner patapp= new Scanner(System.in);
year=patapp.nextInt();
app.setYear(year);
System.out.println("Enter the day "+ap.getId()+" has an appointment");
Scanner dayapp= new Scanner(System.in);
day=dayapp.nextInt();
app.setDay(day);
System.out.println("Enter the month"+ap.getId()+" has an appointment");
Scanner timeapp= new Scanner(System.in);
month=timeapp.nextInt();
app.setMonth(month);
appointments.add(app);
}
Appointment app1= new Appointment();
Patient ap2= new Patient();
Doctor ii2= new Doctor();
for(i=0;i<appointments.size();i++){
app1=appointments.get(i);
ap2=patient.get(i);
ii2=doctor.get(i);
if(ap2.getIllness()==1){
if(ii2.getDocspecialization()==1){
System.out.println("the patient "+ap2.getId()+" is appointed to "+ii2.getDocname());
System.out.println("Appointment of patient"+ap2.getId());
System.out.println(app1.toString());
}
}
if(ap2.getIllness()==2){
if(ii2.getDocspecialization()==2){
System.out.println("the patient "+ap2.getId()+" is appointed to "+ii2.getDocname());
System.out.println("Appointment of patient"+ap2.getId());
System.out.println(app1.toString());
}
}
if(ap2.getIllness()==3){
if(ii2.getDocspecialization()==3){
System.out.println("the patient "+ap2.getId()+" is appointed to "+ii2.getDocname());
System.out.println("Appointment of patient"+ap2.getId());
System.out.println(app1.toString());
}
}
if(ap2.getIllness()==4){
if(ii2.getDocspecialization()==4){
System.out.println("the patient "+ap2.getId()+" is appointed to "+ii2.getDocname());
System.out.println("Appointment of patient"+ap2.getId());
System.out.println(app1.toString());
}
}
if(ap2.getIllness()==5){
if(ii2.getDocspecialization()==5){
System.out.println("the patient "+ap2.getId()+" is appointed to "+ii2.getDocname());
System.out.println("Appointment of patient"+ap2.getId());
System.out.println(app1.toString());
}
}
if(ap2.getIllness()==6){
if(ii2.getDocspecialization()==6){
System.out.println("the patient "+ap2.getId()+" is appointed to "+ii2.getDocname());
System.out.println("Appointment of patient"+ap2.getId());
System.out.println(app1.toString());
}
}
}
}
}