首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >医院管理系统的课程设计与方法

医院管理系统的课程设计与方法
EN

Code Review用户
提问于 2013-08-19 20:59:09
回答 1查看 69.1K关注 0票数 3

我在医院管理系统项目工作。我使用以下设计实现了它。这是个好设计吗?

我创建了四个类:PatientDoctorHospitalDemo。在医院的班级里有两位ArrayLists的病人和医生。此外,在医生类内,有一份病人名单(这是特定医生的特定病人名单)。

在Demo类中,我增加了病人和医生,他们被分别添加到医院类的列表中。

Demo

代码语言:javascript
复制
public class demo {

public static void main (String args[])

{
    Hospital h1= new Hospital("Appollo");
    int choice=0;
    Doctor o = new Doctor("Rai","Surgeon");
    Doctor o1 = new Doctor("James","Opthalmologist");
     Doctor o2 = new Doctor("Steve","ENT");
    System.out.println("Press 1 to add doctor \n Press 2 to show doctors.\n Press 3 to add patient \n 4 Assign doctor to patients\n 5 Doctor and their patients ");
    Scanner cin = new Scanner (System.in);
    choice = cin.nextInt();
    switch (choice)
    {
    case 1:     h1.addDoctor(o);
                    h1.addDoctor(o1);
                    h1.addDoctor(o2);
                  //  break;                
    case 2:    {   System.out.println(h1.showDoctors());

               }    
    case 3:     {   Patient p = new Patient ("Steven ",21,"Male","eye");
                    Patient p1 = new Patient ("Michael ",12,"Male","heart patient");
                    Patient p2 = new Patient ("Sara ",23,"Female","earnose");
                    Patient p3 = new Patient ("Amy ",31,"Female","earnose");
                    Patient p5 = new Patient ("Rocky ",18,"Male","eye");
                    Patient p4= new Patient ("Jessy ",15,"Male","heart patient");
                    h1.addPatient(p);
                    h1.addPatient(p1);
                    h1.addPatient(p2);
                    h1.addPatient(p3);
                    h1.addPatient(p4);
                    h1.addPatient(p5);
                     System.out.println(h1.showPatients());
                }   
    case 4:     {
                     h1.assignDoctor();
                }

    case 5:     {
                      System.out.println("\n \n \n "+ ""+o2.getDoctorName()+""+o2.getDoctorPatientList());
                }
    }
    }}

医院

代码语言:javascript
复制
public class Hospital {

List <Doctor> doctorList = new ArrayList<Doctor>();
List <Patient> patientList = new ArrayList<Patient>();
String hospitalName;
void addDoctor(Doctor o)
{
    doctorList.add(o);

}
void addPatient(Patient o)
{
    patientList.add(o);
}
Hospital(String name)
{
    this.hospitalName=name;
}

public List<Doctor> showDoctors()
{
    return doctorList;
}
public List<Patient> showPatients()
{
    return patientList;
}

public void assignDoctor()
{
    for (Patient x: patientList)
    {      for (Doctor y: doctorList)
            {     if (x.getDisease().equals("eye"))
                        {
                            if (y.getDoctorspeciality().equals("Opthalmologist"))
                                {
                                   y.addPatientsToDoctor(x);
                                }
                        }
            if (x.getDisease().equals("heart patient"))
            {
                if (y.getDoctorspeciality().equals("Surgeon"))
                    {
                       y.addPatientsToDoctor(x);
                    }
            }

            if (x.getDisease().equals("earnose"))
            {
                if (y.getDoctorspeciality().equals("ENT"))
                    {
                       y.addPatientsToDoctor(x);
                    }
            }

            }
        }

}


}

博士

代码语言:javascript
复制
public class Doctor {

private String  doctorName;
private String  doctorSpeciality;
String  doctorStatus;
 List<Patient> doctorPatientList= new ArrayList<Patient>();
Doctor(String c, String cc)
{
    this.doctorName=c;
    this.doctorSpeciality=cc;

}
public String  getDoctorName()
{
    return doctorName;
}

public List<Patient> getDoctorPatientList()
{   
    return doctorPatientList;
}

public void addPatientsToDoctor(Patient o)
{
    doctorPatientList.add(o);
}

String getDoctorspeciality()
{
    return doctorSpeciality;
}
public String toString()
{
    return (doctorName+""+doctorSpeciality);
}

}

患者

代码语言:javascript
复制
public class Patient {
    private String patientName;
    private int patientAge;
    private String  patientGender;
    private String disease;
    Patient (String patientName, int patientAge,String patientGender, String disease)
    {
        this.patientName= patientName;
        this.patientGender= patientGender;
        this.patientAge=patientAge;
        this.disease=disease;
    }   

    public String getDisease()
    {return disease;}

    public String toString()
    {
        return (patientName+""+patientAge+""+patientGender +" "+ disease);
    }
}
EN

回答 1

Code Review用户

发布于 2013-08-19 22:52:55

  • 压痕:到处都是,很难理解。尽量保持一致。
  • 牙套:同样的东西。在大多数情况下,您将它们放在下一行的开头。但是有时候你会用大括号放一行代码。这不是标准惯例之一。使用标准约定比使用非标准约定要好,但无论是哪种情况,您都应该保持一致。
  • 开关支撑:这标志着一个范围范围的区域。这并不意味着你不需要休息声明。
  • 变量名:选择好的变量名:

assignDoctor()

代码语言:javascript
复制
for (Patient x: patientList) {
  for (Doctor y: doctorList) {
    // ...
  }
}

xy是任意的,毫无意义。当你让父亲开始学习时,像patientdoctor这样的名字将会很有帮助。

Hospital中,doctorListpatientList只能是doctorspatients。类型系统会告诉您变量是一个列表。

Doctor中,一切都以“医生”为前缀。它是Doctor的一个字段,因此人们理解该字段属于医生。Patient也是如此。

  • 变量一般情况下:如果只为一件事使用变量,则不需要创建变量。

例如:

代码语言:javascript
复制
Patient p = new Patient ("Steven ",21,"Male","eye");
Patient p1 = new Patient ("Michael ",12,"Male","heart patient");
Patient p2 = new Patient ("Sara ",23,"Female","earnose");
Patient p3 = new Patient ("Amy ",31,"Female","earnose");
Patient p5 = new Patient ("Rocky ",18,"Male","eye");
Patient p4= new Patient ("Jessy ",15,"Male","heart patient");
h1.addPatient(p);
h1.addPatient(p1);
h1.addPatient(p2);
h1.addPatient(p3);
h1.addPatient(p4);
h1.addPatient(p5);

可能只是:

代码语言:javascript
复制
h1.addPatient(new Patient ("Steven ",21,"Male","eye"));
h1.addPatient(new Patient ("Michael ",12,"Male","heart patient"));
// ...
  • 价值:并不是所有的东西都是String。类型系统是用来帮助你的。但是当你把性变成一个String,没有什么能阻止你把"dslkjahgkfdj“当作一个性别。病人的疾病和医生的专业也是如此。你有一套你期待的固定的价值观,但你却为其他许多人敞开了大门。如果病人有“校车”,而唯一的医生专门做“信封”,那么在assignDoctor()会发生什么?enum很可能是这类事物的很好匹配。它允许您定义一组值,并知道您将始终处理该集合中的某些内容。如果您确实决定坚持使用String,则需要将预期值定义为常量。如果明天要将“心脏病人”更改为“心脏病人”,那么更改单个静态最终变量的值就会容易得多,然后在代码库中找到“心脏病人”的所有实例。
票数 8
EN
页面原文内容由Code Review提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://codereview.stackexchange.com/questions/29965

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档