我如何在java中预约记录?

时间:2016-04-16 23:22:09

标签: java

好的,基本上我必须预约医生和患者。我已经记录了医生和患者,但现在我必须预约记录,我必须根据患者的病情和医生的专业情况将一名患者分配给医生。我是java的新手,所以我不是很擅长,所以如果你可以帮助我,我将非常感谢:-)我将向你展示我到目前为止所做的编码。它还包含一些额外的东西,但我必须将它添加到我的作业中。是的,我给一些变量和对象的名字有点奇怪,但这是cos java不会让我给他们一个正确和适当的名称..无论如何这里是我的编码: -

package samplee.java;
import java.util.*;
import java.util.ArrayList;
import java.util.Scanner;

public class patient$ {

    public static void main(String[] args) {
        ArrayList<patientss> patient1= new ArrayList<patientss>();
        ArrayList<doctorss> doctor1= new ArrayList<doctorss>();
        Scanner src= new Scanner(System.in);
        Scanner sc= new Scanner(System.in);
        Scanner stc= new Scanner(System.in);
        Scanner sdc= new Scanner(System.in);
        Scanner update= new Scanner(System.in);
        Scanner ill=new Scanner(System.in);
        int id,it,num,i,docid,docit,docnum,docid1;
        String name,docname,docspecial,illness;
        int ages,docage;
        int id1;
        Boolean leave = false;
        while(!leave){
            patientss xx= new patientss();
            System.out.println("Enter the patient's ID ");
            System.out.println("-1 to finish entering");
            id=src.nextInt();
            if(id != -1){
            xx.setId(id);

        } 
            System.out.println("Enter the patient's name ");
        System.out.println("-1 to finish entering");
        name=stc.next();
        if(id != -1){
            xx.setName(name);
            patient1.add(xx);
        } 
        System.out.println("Enter the patient's phone number");
        System.out.println("-1 to finish entering");
        num=sdc.nextInt();
        if(id != -1){
            xx.setNum(num);
            patient1.add(xx);
        } 
        System.out.println("Enter the type of illness the patient has");
        System.out.println("-1 to finish entering");
        illness=ill.next();
        if(id!= -1){
            xx.setIllness(illness);
            patient1.add(xx);
        }

            else { leave = true; }//Escape the while loop.
        }
        System.out.println("Enter the id of a patient");
        it=sc.nextInt();
        patientss tt= new patientss();
        for(i=0;i<patient1.size();i++)
            {
            tt=patient1.get(i);
            if(it==tt.getId()) 
            System.out.println(tt.toString());
            break;
            }
        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;
        patientss dd= new patientss();
        for(i=0;i<patient1.size();i++){
            dd=patient1.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=update.nextInt();
                if(up==1){
                    System.out.println("Enter a new ID ");
                    Scanner idd= new Scanner(System.in);
                    id2=idd.nextInt();
                    dd.setId(id2);
                    patient1.add(dd);

            }
                else if(up==2){
                    System.out.println("Enter a new name");
                    Scanner namme=new Scanner(System.in);
                    namess=namme.next();
                    dd.setName(namess);
                    patient1.add(dd);

                }
                else if(up==3){
                    System.out.println("Enter a new phone");
                    Scanner newphone= new Scanner(System.in);
                    phones=newphone.nextInt();
                    dd.setNum(phones);
                    patient1.add(dd);

                }
        }
            System.out.println(dd);
            break;
        } 
        boolean over = false;
        while(!over){
            doctorss xt= new doctorss();
            System.out.println("Enter the doctor's ID ");
            System.out.println("-1 to finish entering");
            docid=src.nextInt();
            if(docid != -1){
            xt.setDocid(docid);
            }
            System.out.println("Enter the doctor's name ");
            System.out.println("-1 to finish entering");
            docname=stc.next();
            if(docid != -1){
                xt.setDocname(docname);
                doctor1.add(xt);
            } 
            System.out.println("Enter the doctor's phone number");
            System.out.println("-1 to finish entering");
            docnum=sdc.nextInt();
            if(docid != -1){
                xt.setDocnum(docnum);
                doctor1.add(xt);
            }
            System.out.println("What does the doctor specialize in?");
            String specialize;
            Scanner special= new Scanner(System.in);
            specialize=special.next();
            if(docid != -1){
                xt.setSpecialize(specialize);
                doctor1.add(xt);
            }
                else { over = true; }//Escape the while loop.
            }
        System.out.println("Enter the id of a doctor");
        docit=sc.nextInt();
        doctorss tti= new doctorss();
        for(i=0;i<doctor1.size();i++){
            tti=doctor1.get(i);
            if(docit==tti.getDocid()) 
            System.out.println(tti.toString());
            }

        } 
    }

这些是我的课程..

package samplee.java;

public class patientss {
int id;
String name;
int num;
String illness;
public String getIllness() {
    return illness;
}

public void setIllness(String illness) {
    this.illness = illness;
}

public int getNum() {
    return num;
}

public void setNum(int num) {
    this.num = num;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public int getId() {
    return id;
}

public void setId(int id) {
    this.id = id;
}
public String toString(){
    return name+" "+id+" "+num+ " "+illness;
}
}

这是我的医生班级: -

package samplee.java;

public class doctorss {
int docid;
String specialize;
public String getSpecialize() {
    return specialize;
}
public void setSpecialize(String specialize) {
    this.specialize = specialize;
}
public int getDocid() {
    return docid;
}
public void setDocid(int docid) {
    this.docid = docid;
}
public String getDocname() {
    return docname;
}
public void setDocname(String docname) {
    this.docname = docname;
}
public int getDocnum() {
    return docnum;
}
public void setDocnum(int docnum) {
    this.docnum = docnum;
}
String docname;
int docnum;
public String toString(){
    return docname+" "+docid+" and "+docnum+" he specializes in"+specialize;
}
}

1 个答案:

答案 0 :(得分:1)

首先,我想对您的代码发表一些意见:

  1. 在camel-case启动时遵循Oracle约定和名称类 用大写字母。
  2. 班级名称不得为复数:不是Doctors,而是Doctor。在您的情况下,它描述的是单个实体,而不是一组医生或其他东西。
  3. 没有必要为docidid等字段命名,因为它在Doctor类中已定义。
  4. 我认为疾病必须分开。不幸的是,患者可能患有不同疾病不止一次。
  5. 我建议您使用以下课程(省略getters-setters等详细信息,但我希望您能理解这一点):

    class Doctor {
        private int id;
        private String name;
    }
    
    class Patient {
        private int id;
        private String name;
    }
    
    class Illness {
        private int id;
        private String name;
    }
    
    class Appointment {
        private Doctor doctor;
        private Patient patient;
        private Illness illness;
        private Date date;
    
        public Appointment(
          Doctor doctor, Patient patient, Illness illness, Date date
        ) {
           this.doctor = doctor;
           this.patient = patient;
           this.illness = illness;
           this.date = date;
        }
    }
    

    编辑: 当用户输入医生和患者时,您必须以某种方式“记住”它们。例如,使用数组或ArrayList

    ArrayList<Patient> patients = new ArrayList<Patient>();
    // read the patient here
    patients.add(patient)
    

    因此,在您需要预约的步骤中,您将不得不要求用户输入:医生ID,患者ID,疾病ID和所需日期。然后你必须在“记住的”名单中找到医生,病人和病人:

    Patient patient
    for (Patient item : patients) {
        if (item.getId() == idFromUser) {
            patient = item
        }
    }
    if (patient == null) {
        System.out.println("Patient not found. Choose another ID.");
       // here you have to force user to re-input the value.
    }
    

    然后只需创建新约会:

    new Appointment(doctor, patient, illness, date);