JAVA项目-------医院挂号系统

发布于:2024-11-29 ⋅ 阅读:(11) ⋅ 点赞:(0)

1,项目目的

1、科室管理:新增科室,删除科室(如果有医生在,则不能删除该科室),修改科室。
2、医生管理:录入医生信息,以及科室信息。修改医生信息(主要是修改个人信息和科室)
3、坐诊信息设置:可以设置医生当天和未来6天的坐诊情况,包括上午和下午的坐诊时间段和可预约数量,系统将自动保存到该医生的坐诊信息列表中。
4、全部信息展示:按照科室,展示每个医生七天的坐诊情况,需要按照科室归类展示
5、预约功能:用户可以选择要预约的科室,医生、日期和时间段,并输入患者的个人信息,系统将自动判断该时间段是否还有预约名额,并保存预约信息。
6.搜索功能:用户可以输入搜索日期和时间段,系统将自动搜索未来七天内在该时间段坐诊的医生信息,并按照科室分类展示。
7、可以查询某个医生未来七天,病人对它的预约情况。

2,建立一个部门类

package HostipalSystem;

import java.util.ArrayList;

public class department {
    private String name;
    ArrayList <doctor> doctors=new ArrayList<>();//医生列表

    public department() {
    }

    public department(String name, ArrayList<doctor> doctors) {
        this.name = name;
        this.doctors = doctors;
    }

    public String getName() {
        return name;
    }

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

    public ArrayList<doctor> getDoctors() {
        return doctors;
    }

    public void setDoctors(ArrayList<doctor> doctors) {
        this.doctors = doctors;
    }
}

3,医生类

package HostipalSystem;

import java.time.LocalDate;
import java.util.ArrayList;

public class doctor {
    private String name;
    private String sex;
    private int age;
    private String degree;
    private String advantage;
    private LocalDate jointime;
    private ArrayList<schedule> schedule;//一个医生7天的排版表
    private String department;
    private String id;
    public doctor() {
    }

    public String getDepartment() {
        return department;
    }

    public void setDepartment(String department) {
        this.department = department;
    }

    public doctor(String name, String sex, int age, String degree, String advantage, LocalDate jointime, ArrayList<HostipalSystem.schedule> schedule, String id, String department) {
        this.name = name;
        this.sex = sex;
        this.age = age;
        this.degree = degree;
        this.advantage = advantage;
        this.jointime = jointime;
        this.schedule = schedule;
        this.id = id;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

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

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getDegree() {
        return degree;
    }

    public void setDegree(String degree) {
        this.degree = degree;
    }

    public String getAdvantage() {
        return advantage;
    }

    public void setAdvantage(String advantage) {
        this.advantage = advantage;
    }

    public LocalDate getJointime() {
        return jointime;
    }

    public void setJointime(LocalDate jointime) {
        this.jointime = jointime;
    }

    public ArrayList<HostipalSystem.schedule> getSchedule() {
        return schedule;
    }

    public void setSchedule(ArrayList<HostipalSystem.schedule> schedule) {
        this.schedule = schedule;
    }
}

4,排班类

主要是排班的信息

package HostipalSystem;

import java.time.LocalDate;
import java.time.LocalTime;

public class schedule {
    private LocalDate date;
    private String morning="N";
    private LocalTime starttime;
    private LocalTime endtime;
    private int numjiezhen;
    private int numyuyue;
    private String afternoon="N";
    private LocalTime starttime1;
    private LocalTime endtime1;
    private int numjiezhen1;
    private int numyuyue1;
    private String night="N";
    private LocalTime starttime2;
    private LocalTime endtime2;
    private int numjiezhen2;
    private int numyuyue2;

    public schedule() {
    }

    public schedule(LocalDate date, String morning, LocalTime starttime, LocalTime endtime, int numjiezhen, int numyuyue, String afternoon, LocalTime starttime1, LocalTime endtime1, int numjiezhen1, int numyuyue1, String night, LocalTime starttime2, LocalTime endtime2, int numjiezhen2, int numyuyue2) {
        this.date = date;
        this.morning = morning;
        this.starttime = starttime;
        this.endtime = endtime;
        this.numjiezhen = numjiezhen;
        this.numyuyue = numyuyue;
        this.afternoon = afternoon;
        this.starttime1 = starttime1;
        this.endtime1 = endtime1;
        this.numjiezhen1 = numjiezhen1;
        this.numyuyue1 = numyuyue1;
        this.night = night;
        this.starttime2 = starttime2;
        this.endtime2 = endtime2;
        this.numjiezhen2 = numjiezhen2;
        this.numyuyue2 = numyuyue2;
    }

    public LocalDate getDate() {
        return date;
    }

    public void setDate(LocalDate date) {
        this.date = date;
    }

    public String getMorning() {
        return morning;
    }

    public void setMorning(String morning) {
        this.morning = morning;
    }

    public LocalTime getStarttime() {
        return starttime;
    }

    public void setStarttime(LocalTime starttime) {
        this.starttime = starttime;
    }

    public LocalTime getEndtime() {
        return endtime;
    }

    public void setEndtime(LocalTime endtime) {
        this.endtime = endtime;
    }

    public int getNumjiezhen() {
        return numjiezhen;
    }

    public void setNumjiezhen(int numjiezhen) {
        this.numjiezhen = numjiezhen;
    }

    public int getNumyuyue() {
        return numyuyue;
    }

    public void setNumyuyue(int numyuyue) {
        this.numyuyue = numyuyue;
    }

    public String getAfternoon() {
        return afternoon;
    }

    public void setAfternoon(String afternoon) {
        this.afternoon = afternoon;
    }

    public LocalTime getStarttime1() {
        return starttime1;
    }

    public void setStarttime1(LocalTime starttime1) {
        this.starttime1 = starttime1;
    }

    public LocalTime getEndtime1() {
        return endtime1;
    }

    public void setEndtime1(LocalTime endtime1) {
        this.endtime1 = endtime1;
    }

    public int getNumjiezhen1() {
        return numjiezhen1;
    }

    public void setNumjiezhen1(int numjiezhen1) {
        this.numjiezhen1 = numjiezhen1;
    }

    public int getNumyuyue1() {
        return numyuyue1;
    }

    public void setNumyuyue1(int numyuyue1) {
        this.numyuyue1 = numyuyue1;
    }

    public String getNight() {
        return night;
    }

    public void setNight(String night) {
        this.night = night;
    }

    public LocalTime getStarttime2() {
        return starttime2;
    }

    public void setStarttime2(LocalTime starttime2) {
        this.starttime2 = starttime2;
    }

    public LocalTime getEndtime2() {
        return endtime2;
    }

    public void setEndtime2(LocalTime endtime2) {
        this.endtime2 = endtime2;
    }

    public int getNumjiezhen2() {
        return numjiezhen2;
    }

    public void setNumjiezhen2(int numjiezhen2) {
        this.numjiezhen2 = numjiezhen2;
    }

    public int getNumyuyue2() {
        return numyuyue2;
    }

    public void setNumyuyue2(int numyuyue2) {
        this.numyuyue2 = numyuyue2;
    }
}

4,预约类

主要是病人的信息

package HostipalSystem;

import java.time.LocalDateTime;

public class oppintment {
    private  int num=0;
    private String name;
    private String sex;
    private int age;
    private String desc;
    private String doctor;
    private String departmentname;
    private LocalDateTime date;

    public oppintment() {
    }

    public int getNum() {
        return num;
    }

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

    public oppintment(String name, String sex, int age, String desc, String doctor, String departmentname, LocalDateTime date, int num) {
        this.name = name;
        this.sex = sex;
        this.age = age;
        this.desc = desc;
        this.doctor = doctor;
        this.departmentname = departmentname;
        this.date = date;
        this.num=num;
    }

    public String getName() {
        return name;
    }

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

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public String getDoctor() {
        return doctor;
    }

    public void setDoctor(String doctor) {
        this.doctor = doctor;
    }

    public String getDepartmentname() {
        return departmentname;
    }

    public void setDepartmentname(String departmentname) {
        this.departmentname = departmentname;
    }

    public LocalDateTime getDate() {
        return date;
    }

    public void setDate(LocalDateTime date) {
        this.date = date;
    }
}

6,医院操着系统

6.1界面

public void start()
    {
        Boolean flag=true;
        while(flag)
        {
            Scanner sc= new Scanner(System.in);
            System.out.println("------------欢迎来到医院操作系统-------------");
            System.out.println("----------1,添加部门------------");
            System.out.println("----------2,添加医生------------");
            System.out.println("----------3,查询部门里的医生------------");
            System.out.println("----------4,查询医生的基本信息------------");
            System.out.println("----------5,查询可预约医生的时间------------");
            System.out.println("----------6,挂号------------");
            System.out.println("----------7,排班------------");
            System.out.println("----------8,退出操作系统------------");
            int command=sc.nextInt();
            switch (command)
            {
                case 1:
                    adddepasrtment();
                    break;
                case 2:
                    adddoctor();
                    break;
                case 3:
                    showdoctorindepartment();
                    break;
                case 4:
                    showdoctorinfo();
                    break;
                case 5:
                    showtimeofdoctor();
                    break;
                case 6:
                    booking();
                    break;
                case 8:
                    flag=false;
                    break;
                case 7:
                        operateschedule();
                        break;
                default:
                    System.out.println("输入有误,请重新输入");
            }
        }
    }

6.2设置部门

需要判断部门是否存在

public void adddepasrtment()
    {
        OUT:
        while(true)
        {
            department d=new department();
            Scanner sc=new Scanner(System.in);
            System.out.println("请输入你要添加的部门的名称");
            String name=sc.next();
            d.setName(name);
            for(int i=0;i<alldepartment.size();i++)
            {
                if(alldepartment.get(i).getName().equals(name))
                {
                    System.out.println("该部门已存在");
                    continue OUT;
                }
            }
            alldepartment.add(d);//将建好的部门添加进去
            break;
        }
    }

6.2.1遇到问题1

            Scanner sc=new Scanner(System.in);
            System.out.println("请输入你要添加的部门的名称");
            String name=sc.next();

将以上输入语句放在外面,如果不合格将一直循环

错误代码如下:

public void adddepasrtment()
    {
        OUT:
        department d=new department();
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入你要添加的部门的名称");
        String name=sc.next();
        while(true)
        {
            Scanner sc=new Scanner(System.in);
            System.out.println("请输入你要添加的部门的名称");
            String name=sc.next();
            d.setName(name);
            for(int i=0;i<alldepartment.size();i++)
            {
                if(alldepartment.get(i).getName().equals(name))
                {
                    System.out.println("该部门已存在");
                    continue OUT;
                }
            }
            alldepartment.add(d);
            break;
        }
    }

6.2.2遇到问题2

OUT:放在循环外面;

continue OUT放在循环里面结束一层循环

6.3建立一个存放部门的集合

ArrayList<department> alldepartment=new ArrayList<>();

7,医生的添加

public void adddoctor()
    {
        doctor d=new doctor();
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入你要添加的医生的姓名");
        String name=sc.next();
        d.setName(name);
        System.out.println("请输入你要添加的医生的性别");
        String sex=sc.next();
        d.setSex(sex);
        System.out.println("请输入你要添加的医生的年龄");
        int age=sc.nextInt();
        d.setAge(age);
        System.out.println("请输入你要添加的医生的学历");
        String degree=sc.next();
        d.setDegree(degree);
        System.out.println("请输入你要添加的医生的擅长");
        String advantage=sc.next();
        d.setAdvantage(advantage);
        System.out.println("请输入你要添加的医生的入职时间");
        //LocalDate jointime=sc.nextLocalDate();
        d.setJointime(jointime());//调用方法存入医生的入职时间
        d.setId(UUID.randomUUID().toString());//生成随机数作为医生的编号
        System.out.println("您的编号是"+d.getId());
        System.out.println("请选择你的部门");
        for(int i=0;i<alldepartment.size();i++)
        {
            System.out.println(i+1+"."+alldepartment.get(i).getName());
        }
        while(true)
        {
            System.out.println("请输入部门的编号");
            int command=sc.nextInt();
            if(command>alldepartment.size()||command<1)
            {
                System.out.println("输入有误,请重新输入");
                continue;
            }
            else
            {
                d.setDepartment(alldepartment.get(command-1).getName());
                alldepartment.get(command-1).getDoctors().add(d);
                alldoctor.add(d);//将医生添加到科室里
                System.out.println("录入完毕");
                break;
            }
        }
    }

7.1医生的加入时间

public LocalDate jointime()
    {
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入医生入职时间格式为yyyy-mm-dd");
        String jointime=sc.next();
        LocalDate date=LocalDate.parse(jointime);
        return date;
    }

7.2写一个集合存放所有医生

ArrayList<doctor> alldoctor=new ArrayList<>();

8,查询部门里的医生

public void showdoctorindepartment()
    {
        for(int i=0;i<alldepartment.size();i++)
        {
            System.out.println(i+1+"."+alldepartment.get(i).getName());
        }
        while(true)
        {
            System.out.println("请输入你想了解的部门的编号");
            Scanner sc=new Scanner(System.in);
            int command=sc.nextInt();
            if(command>alldepartment.size()||command<1)
            {
                System.out.println("输入有误,请重新输入");
                continue;
            }
            else
            {

                for (int i = 0; i < alldepartment.get(command-1).getDoctors().size(); i++)
                {
                    System.out.println(alldepartment.get(command-1).getDoctors().get(i).getName());
                }
                break;
            }
        }
    }

9,查询医生的全部信息

public void showdoctorinfo()
    {
        for (int i = 0; i < alldoctor.size(); i++)
        {
            System.out.println(alldoctor.get(i).getName());
            System.out.println(alldoctor.get(i).getSex());
            System.out.println(alldoctor.get(i).getAge());
            System.out.println(alldoctor.get(i).getDegree());
            System.out.println(alldoctor.get(i).getAdvantage());
            System.out.println(alldoctor.get(i).getJointime());
            System.out.println(alldoctor.get(i).getId());
            System.out.println(alldoctor.get(i).getDepartment());
            System.out.println("---------------------------------------");
        }
    }

10,查找需要的医生

public doctor printfalldoctor (){
        for(int i=0;i<alldoctor.size();i++)
        {
            System.out.println((i+1)+alldoctor.get(i).getName());
        }

        doctor d;
        while(true)
        {
            System.out.println("请输入你想了解的医生的编号");
            Scanner sc=new Scanner(System.in);
            int command=sc.nextInt();
            if(command>alldoctor.size()||command<1)
            {
                System.out.println("输入有误,请重新输入");
                continue;
            }
            else
            {
                d=alldoctor.get(command-1);
                break;
            }
        }
        return d;//返回医生
    }

11排班

public void operateschedule()
    {
        doctor d=printfalldoctor();
        for (int i = 0; i < 7; i++)
        {
            schedule s=new schedule();
            s.setDate(LocalDate.now().plusDays(i));
            System.out.println("请输入"+s.getDate()+"号星期"+s.getDate().getDayOfWeek()+"上午是否上班");//s.getDate().getDayOfWeek()取的是日对象的获得星期天的方法
            System.out.println("Y,上班");
            System.out.println("N,不上班");
            Scanner sc=new Scanner(System.in);
            String command=sc.next();
            s.setMorning(command);
            if(s.getMorning().equals("Y"))
            {
                System.out.println("请输入"+s.getDate()+"号星期"+s.getDate().getDayOfWeek()+"的上午上班时间");
                System.out.println("格式为HH:mm:ss");
                String starttime=sc.next();
                s.setStarttime(LocalTime.parse(starttime));
                System.out.println("请输入"+s.getDate()+"号星期"+s.getDate().getDayOfWeek()+"的上午下班时间");
                System.out.println("格式为HH:mm:ss");
                String endtime=sc.next();
                s.setEndtime(LocalTime.parse(endtime));
                System.out.println("请输入"+s.getDate()+"号星期"+s.getDate().getDayOfWeek()+"的上午接诊人数");
                int numjiezhen=sc.nextInt();
                s.setNumjiezhen(numjiezhen);
            }

            System.out.println("请输入"+s.getDate()+"号星期"+s.getDate().getDayOfWeek()+"下午是否上班");
            System.out.println("Y,上班");
            System.out.println("N,不上班");
            String command1=sc.next();
            s.setAfternoon(command1);
            if(s.getAfternoon().equals("Y"))
            {
                System.out.println("请输入"+s.getDate()+"号星期"+s.getDate().getDayOfWeek()+"下午上班时间");
                System.out.println("格式为HH:mm:ss");
                String starttime1=sc.next();
                s.setStarttime1(LocalTime.parse(starttime1));
                System.out.println("请输入"+s.getDate()+"号星期"+s.getDate().getDayOfWeek()+"下午下班时间");
                System.out.println("格式为HH:mm:ss");
                String endtime1=sc.next();
                s.setEndtime1(LocalTime.parse(endtime1));
                System.out.println("请输入"+s.getDate()+"号星期"+s.getDate().getDayOfWeek()+"下午接诊人数");
                int numjiezhen1=sc.nextInt();
                s.setNumjiezhen1(numjiezhen1);
            }
            System.out.println("请输入"+s.getDate()+"号星期"+s.getDate().getDayOfWeek()+"晚上是否上班");
            System.out.println("Y,上班");
            System.out.println("N,不上班");
            String command2=sc.next();
            s.setNight(command2);
            if(s.getNight().equals("Y"))
            {
                System.out.println("请输入"+s.getDate()+"号星期"+s.getDate().getDayOfWeek()+"晚上上班时间");
                System.out.println("格式为HH:mm:ss");
                String starttime2=sc.next();
                s.setStarttime2(LocalTime.parse(starttime2));
                System.out.println("请输入"+s.getDate()+"号星期"+s.getDate().getDayOfWeek()+"晚上下班时间");
                System.out.println("格式为HH:mm:ss");
                String endtime2=sc.next();
                s.setEndtime2(LocalTime.parse(endtime2));
                System.out.println("请输入"+s.getDate()+"号星期"+s.getDate().getDayOfWeek()+"晚上接诊人数");
                int numjiezhen2=sc.nextInt();
                s.setNumjiezhen2(numjiezhen2);
            }
            d.getSchedule().add(s);//添加排班
        }

    }

12,查询信息医生排班

public void showtimeofdoctor()
    {
        doctor d=printfalldoctor();//调用方法获取输入的医生
        for (int i = 0; i < d.getSchedule().size(); i++)
        {
            System.out.println(d.getSchedule().get(i).getDate());
            if(d.getSchedule().get(i).getMorning().equals("Y"))
            {
                System.out.println("上午:"+d.getSchedule().get(i).getStarttime()+"-"+d.getSchedule().get(i).getEndtime());
                System.out.println("预约人数:"+d.getSchedule().get(i).getNumyuyue()+"接诊人数:"+d.getSchedule().get(i).getNumjiezhen());
            }
            else if(d.getSchedule().get(i).getMorning().equals("N")) System.out.println("上午不上班");
            if(d.getSchedule().get(i).getAfternoon().equals("Y"))
            {
                System.out.println("下午:"+d.getSchedule().get(i).getStarttime1()+"-"+d.getSchedule().get(i).getEndtime1());
                System.out.println("预约人数:"+d.getSchedule().get(i).getNumyuyue1()+"接诊人数:"+d.getSchedule().get(i).getNumjiezhen1());
            }
            else if(d.getSchedule().get(i).getAfternoon().equals("N")) System.out.println("下午不上班");
            if(d.getSchedule().get(i).getNight().equals("Y"))
            {
                System.out.println("晚上:"+d.getSchedule().get(i).getStarttime2()+"-"+d.getSchedule().get(i).getEndtime2());
                System.out.println("预约人数:"+d.getSchedule().get(i).getNumyuyue2()+"接诊人数:"+d.getSchedule().get(i).getNumjiezhen2());
                System.out.println("---------------------------------------");
            }
        }
    }

13,遇到问题字符串与时间对象的格式转换

如果你遇到 LocalTime.parse() 方法无法解析时间字符串的问题,通常有以下几个原因:
格式不匹配:
输入的时间字符串格式与 LocalTime.parse() 默认的格式(HH:mm:ss)不匹配。
解决方法:使用 DateTimeFormatter 指定正确的格式。
无效的时间值:
输入的时间字符串包含无效的时间值,例如小时数超过23,分钟数或秒数超过59。
解决方法:确保输入的时间字符串是有效的。
字符集问题:
输入的时间字符串包含非数字字符或特殊字符。
解决方法:检查并清理输入字符串,确保只有有效的时间字符。
时区问题:
如果时间字符串包含时区信息,而 LocalTime 不支持时区。
解决方法:使用 ZonedDateTime 或 OffsetTime 来处理带时区的时间字符串。

LocalDate.parse() 方法默认使用 ISO_LOCAL_DATE 格式,即 yyyy-MM-dd。如果你的输入时间字符串格式与此默认格式不匹配,你需要使用 DateTimeFormatter 来指定正确的格式。

14,病人预约

14.1预约成功后打印信息

public oppintment bookingsc(oppintment o,doctor d)
    {
        System.out.println("请输入您的姓名");
        Scanner sc=new Scanner(System.in);
        String name=sc.next();
        o.setName(name);
        System.out.println("请输入您的性别");
        String sex=sc.next();
        o.setSex(sex);
        System.out.println("请输入您的年龄");
        int age=sc.nextInt();
        o.setAge(age);
        System.out.println("请输入您的手机号");
        String phone=sc.next();
        o.setDesc(phone);
        System.out.println("预约成功");
        System.out.println("预约科室:"+d.getDepartment());
        o.setDepartmentname(d.getDepartment());
        System.out.println("预约医生:"+d.getName());
        o.setDoctor(d.getName());
        System.out.println("预约号:"+o.getNum()+1);
        o.setNum(o.getNum()+1);
        return o;
    }

}

14.2能否预约成功进行判断

public void booking()
    {
        doctor d=printfalldoctor();
        oppintment o=new oppintment();
        System.out.println("请输入预约日期");
        Scanner sc=new Scanner(System.in);
        String date=sc.next();
        LocalDate date1=LocalDate.parse(date);
        for(int i=0;i<d.getSchedule().size();i++)
        {
            schedule s=d.getSchedule().get(i);
            if(s.equals(date1))
            {
                System.out.println("请选择1,上午。2,下午。3,晚上");
                int command=sc.nextInt();
                switch (command)
                {
                    case 1:
                        if(s.getMorning().equals("Y"))
                        {
                            System.out.println("请输入预约时间");
                            String time=sc.next();
                            LocalTime time1=LocalTime.parse(time);
                            if(time1.isBefore(s.getEndtime())&&time1.isAfter(s.getStarttime())&&(s.getNumjiezhen()-s.getNumyuyue())>0)//判断是否在范围内,预约人数是否满了
                            {
                                oppintment o1=bookingsc(o,d);

                                LocalDateTime date2=LocalDateTime.of(date1,time1);
                                o1.setDate(date2);
                                System.out.println("预约时间"+date2);
                                allpaitent.add(o1);
                            }
                        }
                        break;
                    case 2:
                        if(s.getAfternoon().equals("Y"))
                        {
                            System.out.println("请输入预约时间");
                            String time=sc.next();
                            LocalTime time1=LocalTime.parse(time);
                            if(time1.isBefore(s.getEndtime1())&&time1.isAfter(s.getStarttime1())&&(s.getNumjiezhen1()-s.getNumyuyue1())>0)
                            {
                               oppintment o1=bookingsc(o,d);
                               LocalDateTime date2=LocalDateTime.of(date1,time1);
                               o1.setDate(date2);
                               System.out.println("预约时间"+date2);
                               allpaitent.add(o1);
                            }
                        }
                        break;
                    case 3:
                        if(s.getNight().equals("Y"))
                        {
                            System.out.println("请输入预约时间");
                            String time=sc.next();
                            LocalTime time1=LocalTime.parse(time);
                            if(time1.isBefore(s.getEndtime2())&&time1.isAfter(s.getStarttime2())&&(s.getNumjiezhen2()-s.getNumyuyue2())>0)
                            {
                               oppintment o1=bookingsc(o,d);//预约成功,打印基本信息
                               LocalDateTime date2=LocalDateTime.of(date1,time1);
                               o1.setDate(date2);
                               System.out.println("预约时间"+date2);//最后打印时间
                               allpaitent.add(o1);
                            }
                        }
                       break;
                    default:
                        System.out.println("输入有误,请重新输入");
                        continue;
                }
            }
        }
    }

14.3代码解释

这段代码实现了医院预约系统的预约功能。具体步骤如下:
选择医生:调用 printfalldoctor 方法显示所有医生,并让用户选择一个医生。
创建预约对象:创建一个新的 oppintment 对象。
输入预约日期:用户输入预约日期,并将其转换为 LocalDate 对象。
遍历医生的排班表:检查医生的排班表,找到与用户输入日期匹配的排班记录。
选择时间段:用户选择上午、下午或晚上的时间段。
输入预约时间:用户输入具体的预约时间,并进行验证。
验证预约时间:确保预约时间在医生的工作时间内,并且预约人数未满。
完成预约:调用 bookingsc 方法完成预约,并将预约信息添加到 allpaitent 列表中。

15,app 实现类

package HostipalSystem;

import java.time.LocalDate;
import java.util.Scanner;

public class app {
    public static void main(String[] args) {
        hospitalmanager h=new hospitalmanager();
        h.start();
    }
}

16超卓系统全部代码

package HostipalSystem;

import javax.swing.text.DateFormatter;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.UUID;

public class hospitalmanager
{
    ArrayList<department> alldepartment=new ArrayList<>();
    ArrayList<doctor> alldoctor=new ArrayList<>();
    ArrayList<oppintment> allpaitent=new ArrayList<>();

    public void start()
    {
        Boolean flag=true;
        while(flag)
        {
            Scanner sc= new Scanner(System.in);
            System.out.println("------------欢迎来到医院操作系统-------------");
            System.out.println("----------1,添加部门------------");
            System.out.println("----------2,添加医生------------");
            System.out.println("----------3,查询部门里的医生------------");
            System.out.println("----------4,查询医生的基本信息------------");
            System.out.println("----------5,查询可预约医生的时间------------");
            System.out.println("----------6,挂号------------");
            System.out.println("----------7,排班------------");
            System.out.println("----------8,退出操作系统------------");
            int command=sc.nextInt();
            switch (command)
            {
                case 1:
                    adddepasrtment();
                    break;
                case 2:
                    adddoctor();
                    break;
                case 3:
                    showdoctorindepartment();
                    break;
                case 4:
                    showdoctorinfo();
                    break;
                case 5:
                    showtimeofdoctor();
                    break;
                case 6:
                    booking();
                    break;
                case 8:
                    flag=false;
                    break;
                case 7:
                        operateschedule();
                        break;
                default:
                    System.out.println("输入有误,请重新输入");
            }
        }
    }
    public void adddepasrtment()
    {
        OUT:
        while(true)
        {
            department d=new department();
            Scanner sc=new Scanner(System.in);
            System.out.println("请输入你要添加的部门的名称");
            String name=sc.next();
            d.setName(name);
            for(int i=0;i<alldepartment.size();i++)
            {
                if(alldepartment.get(i).getName().equals(name))
                {
                    System.out.println("该部门已存在");
                    continue OUT;
                }
            }
            alldepartment.add(d);//将建好的部门添加进去
            break;
        }
    }
    public void adddoctor()
    {
        doctor d=new doctor();
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入你要添加的医生的姓名");
        String name=sc.next();
        d.setName(name);
        System.out.println("请输入你要添加的医生的性别");
        String sex=sc.next();
        d.setSex(sex);
        System.out.println("请输入你要添加的医生的年龄");
        int age=sc.nextInt();
        d.setAge(age);
        System.out.println("请输入你要添加的医生的学历");
        String degree=sc.next();
        d.setDegree(degree);
        System.out.println("请输入你要添加的医生的擅长");
        String advantage=sc.next();
        d.setAdvantage(advantage);
        System.out.println("请输入你要添加的医生的入职时间");
        //LocalDate jointime=sc.nextLocalDate();
        d.setJointime(jointime());//调用方法存入医生的入职时间
        d.setId(UUID.randomUUID().toString());//生成随机数作为医生的编号
        System.out.println("您的编号是"+d.getId());
        System.out.println("请选择你的部门");
        for(int i=0;i<alldepartment.size();i++)
        {
            System.out.println(i+1+"."+alldepartment.get(i).getName());
        }
        while(true)
        {
            System.out.println("请输入部门的编号");
            int command=sc.nextInt();
            if(command>alldepartment.size()||command<1)
            {
                System.out.println("输入有误,请重新输入");
                continue;
            }
            else
            {
                d.setDepartment(alldepartment.get(command-1).getName());
                alldepartment.get(command-1).getDoctors().add(d);
                alldoctor.add(d);//将医生添加到科室里
                System.out.println("录入完毕");
                break;
            }
        }
    }
    public LocalDate jointime()
    {
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入医生入职时间格式为yyyy-mm-dd");
        String jointime=sc.next();
        LocalDate date=LocalDate.parse(jointime);
        return date;
    }
    public void showdoctorindepartment()
    {
        for(int i=0;i<alldepartment.size();i++)
        {
            System.out.println(i+1+"."+alldepartment.get(i).getName());
        }
        while(true)
        {
            System.out.println("请输入你想了解的部门的编号");
            Scanner sc=new Scanner(System.in);
            int command=sc.nextInt();
            if(command>alldepartment.size()||command<1)
            {
                System.out.println("输入有误,请重新输入");
                continue;
            }
            else
            {

                for (int i = 0; i < alldepartment.get(command-1).getDoctors().size(); i++)
                {
                    System.out.println(alldepartment.get(command-1).getDoctors().get(i).getName());
                }
                break;
            }
        }
    }
    public void showdoctorinfo()
    {
        for (int i = 0; i < alldoctor.size(); i++)
        {
            System.out.println(alldoctor.get(i).getName());
            System.out.println(alldoctor.get(i).getSex());
            System.out.println(alldoctor.get(i).getAge());
            System.out.println(alldoctor.get(i).getDegree());
            System.out.println(alldoctor.get(i).getAdvantage());
            System.out.println(alldoctor.get(i).getJointime());
            System.out.println(alldoctor.get(i).getId());
            System.out.println(alldoctor.get(i).getDepartment());
            System.out.println("---------------------------------------");
        }
    }
    public void showtimeofdoctor()
    {
        doctor d=printfalldoctor();//调用方法获取输入的医生
        for (int i = 0; i < d.getSchedule().size(); i++)
        {
            System.out.println(d.getSchedule().get(i).getDate());
            if(d.getSchedule().get(i).getMorning().equals("Y"))
            {
                System.out.println("上午:"+d.getSchedule().get(i).getStarttime()+"-"+d.getSchedule().get(i).getEndtime());
                System.out.println("预约人数:"+d.getSchedule().get(i).getNumyuyue()+"接诊人数:"+d.getSchedule().get(i).getNumjiezhen());
            }
            else if(d.getSchedule().get(i).getMorning().equals("N")) System.out.println("上午不上班");
            if(d.getSchedule().get(i).getAfternoon().equals("Y"))
            {
                System.out.println("下午:"+d.getSchedule().get(i).getStarttime1()+"-"+d.getSchedule().get(i).getEndtime1());
                System.out.println("预约人数:"+d.getSchedule().get(i).getNumyuyue1()+"接诊人数:"+d.getSchedule().get(i).getNumjiezhen1());
            }
            else if(d.getSchedule().get(i).getAfternoon().equals("N")) System.out.println("下午不上班");
            if(d.getSchedule().get(i).getNight().equals("Y"))
            {
                System.out.println("晚上:"+d.getSchedule().get(i).getStarttime2()+"-"+d.getSchedule().get(i).getEndtime2());
                System.out.println("预约人数:"+d.getSchedule().get(i).getNumyuyue2()+"接诊人数:"+d.getSchedule().get(i).getNumjiezhen2());
                System.out.println("---------------------------------------");
            }
        }
    }
    //
    public doctor printfalldoctor (){
        for(int i=0;i<alldoctor.size();i++)
        {
            System.out.println((i+1)+alldoctor.get(i).getName());
        }

        doctor d;
        while(true)
        {
            System.out.println("请输入你想了解的医生的编号");
            Scanner sc=new Scanner(System.in);
            int command=sc.nextInt();
            if(command>alldoctor.size()||command<1)
            {
                System.out.println("输入有误,请重新输入");
                continue;
            }
            else
            {
                d=alldoctor.get(command-1);
                break;
            }
        }
        return d;//返回医生
    }
    public void operateschedule()
    {
        doctor d=printfalldoctor();
        for (int i = 0; i < 7; i++)
        {
            schedule s=new schedule();
            s.setDate(LocalDate.now().plusDays(i));
            System.out.println("请输入"+s.getDate()+"号星期"+s.getDate().getDayOfWeek()+"上午是否上班");//s.getDate().getDayOfWeek()取的是日对象的获得星期天的方法
            System.out.println("Y,上班");
            System.out.println("N,不上班");
            Scanner sc=new Scanner(System.in);
            String command=sc.next();
            s.setMorning(command);
            if(s.getMorning().equals("Y"))
            {
                System.out.println("请输入"+s.getDate()+"号星期"+s.getDate().getDayOfWeek()+"的上午上班时间");
                System.out.println("格式为HH:mm:ss");
                String starttime=sc.next();
                s.setStarttime(LocalTime.parse(starttime));
                System.out.println("请输入"+s.getDate()+"号星期"+s.getDate().getDayOfWeek()+"的上午下班时间");
                System.out.println("格式为HH:mm:ss");
                String endtime=sc.next();
                s.setEndtime(LocalTime.parse(endtime));
                System.out.println("请输入"+s.getDate()+"号星期"+s.getDate().getDayOfWeek()+"的上午接诊人数");
                int numjiezhen=sc.nextInt();
                s.setNumjiezhen(numjiezhen);
            }

            System.out.println("请输入"+s.getDate()+"号星期"+s.getDate().getDayOfWeek()+"下午是否上班");
            System.out.println("Y,上班");
            System.out.println("N,不上班");
            String command1=sc.next();
            s.setAfternoon(command1);
            if(s.getAfternoon().equals("Y"))
            {
                System.out.println("请输入"+s.getDate()+"号星期"+s.getDate().getDayOfWeek()+"下午上班时间");
                System.out.println("格式为HH:mm:ss");
                String starttime1=sc.next();
                s.setStarttime1(LocalTime.parse(starttime1));
                System.out.println("请输入"+s.getDate()+"号星期"+s.getDate().getDayOfWeek()+"下午下班时间");
                System.out.println("格式为HH:mm:ss");
                String endtime1=sc.next();
                s.setEndtime1(LocalTime.parse(endtime1));
                System.out.println("请输入"+s.getDate()+"号星期"+s.getDate().getDayOfWeek()+"下午接诊人数");
                int numjiezhen1=sc.nextInt();
                s.setNumjiezhen1(numjiezhen1);
            }
            System.out.println("请输入"+s.getDate()+"号星期"+s.getDate().getDayOfWeek()+"晚上是否上班");
            System.out.println("Y,上班");
            System.out.println("N,不上班");
            String command2=sc.next();
            s.setNight(command2);
            if(s.getNight().equals("Y"))
            {
                System.out.println("请输入"+s.getDate()+"号星期"+s.getDate().getDayOfWeek()+"晚上上班时间");
                System.out.println("格式为HH:mm:ss");
                String starttime2=sc.next();
                s.setStarttime2(LocalTime.parse(starttime2));
                System.out.println("请输入"+s.getDate()+"号星期"+s.getDate().getDayOfWeek()+"晚上下班时间");
                System.out.println("格式为HH:mm:ss");
                String endtime2=sc.next();
                s.setEndtime2(LocalTime.parse(endtime2));
                System.out.println("请输入"+s.getDate()+"号星期"+s.getDate().getDayOfWeek()+"晚上接诊人数");
                int numjiezhen2=sc.nextInt();
                s.setNumjiezhen2(numjiezhen2);
            }
            d.getSchedule().add(s);//添加排班
        }

    }
    public void booking()
    {
        doctor d=printfalldoctor();
        oppintment o=new oppintment();
        System.out.println("请输入预约日期");
        Scanner sc=new Scanner(System.in);
        String date=sc.next();
        LocalDate date1=LocalDate.parse(date);
        for(int i=0;i<d.getSchedule().size();i++)
        {
            schedule s=d.getSchedule().get(i);
            if(s.equals(date1))
            {
                System.out.println("请选择1,上午。2,下午。3,晚上");
                int command=sc.nextInt();
                switch (command)
                {
                    case 1:
                        if(s.getMorning().equals("Y"))
                        {
                            System.out.println("请输入预约时间");
                            String time=sc.next();
                            LocalTime time1=LocalTime.parse(time);
                            if(time1.isBefore(s.getEndtime())&&time1.isAfter(s.getStarttime())&&(s.getNumjiezhen()-s.getNumyuyue())>0)//判断是否在范围内,预约人数是否满了
                            {
                                oppintment o1=bookingsc(o,d);

                                LocalDateTime date2=LocalDateTime.of(date1,time1);
                                o1.setDate(date2);
                                System.out.println("预约时间"+date2);
                                allpaitent.add(o1);
                            }
                        }
                        break;
                    case 2:
                        if(s.getAfternoon().equals("Y"))
                        {
                            System.out.println("请输入预约时间");
                            String time=sc.next();
                            LocalTime time1=LocalTime.parse(time);
                            if(time1.isBefore(s.getEndtime1())&&time1.isAfter(s.getStarttime1())&&(s.getNumjiezhen1()-s.getNumyuyue1())>0)
                            {
                               oppintment o1=bookingsc(o,d);
                               LocalDateTime date2=LocalDateTime.of(date1,time1);
                               o1.setDate(date2);
                               System.out.println("预约时间"+date2);
                               allpaitent.add(o1);
                            }
                        }
                        break;
                    case 3:
                        if(s.getNight().equals("Y"))
                        {
                            System.out.println("请输入预约时间");
                            String time=sc.next();
                            LocalTime time1=LocalTime.parse(time);
                            if(time1.isBefore(s.getEndtime2())&&time1.isAfter(s.getStarttime2())&&(s.getNumjiezhen2()-s.getNumyuyue2())>0)
                            {
                               oppintment o1=bookingsc(o,d);//预约成功,打印基本信息
                               LocalDateTime date2=LocalDateTime.of(date1,time1);
                               o1.setDate(date2);
                               System.out.println("预约时间"+date2);//最后打印时间
                               allpaitent.add(o1);
                            }
                        }
                       break;
                    default:
                        System.out.println("输入有误,请重新输入");
                        continue;
                }
            }
        }
    }
    public oppintment bookingsc(oppintment o,doctor d)
    {
        System.out.println("请输入您的姓名");
        Scanner sc=new Scanner(System.in);
        String name=sc.next();
        o.setName(name);
        System.out.println("请输入您的性别");
        String sex=sc.next();
        o.setSex(sex);
        System.out.println("请输入您的年龄");
        int age=sc.nextInt();
        o.setAge(age);
        System.out.println("请输入您的手机号");
        String phone=sc.next();
        o.setDesc(phone);
        System.out.println("预约成功");
        System.out.println("预约科室:"+d.getDepartment());
        o.setDepartmentname(d.getDepartment());
        System.out.println("预约医生:"+d.getName());
        o.setDoctor(d.getName());
        System.out.println("预约号:"+o.getNum()+1);
        o.setNum(o.getNum()+1);
        return o;
    }

}