「已注销」 2023-02-20 15:55 采纳率: 50%
浏览 56
已结题

如何用java实现幼儿园管理系统的名额问题?

实现 Schoolsystem类

  1. Schoolsystem( Integer big, Integer medium, Integer small)l初始化Schoolsystem类,三个参数分别对应每种班级的剩余名额。
    (2) bool addstudert( Integer stu ype)检查是否有 stutype对应的班级。 stutypet有三种类型:大,中,小,分别用数字1,2和3表示。一个学生只能在 stutype对应的班级中。如果没有剩余多的班级人数,请返回 false,否则将该学生录入班级井返回true
    (3) Stringl parse( String input)解析输入字符串(格式见示列)返回字符串数组
    (4) void printi()输出结果(格式见示例)
    r'scholsystem, addstuden "adcstudert" addstudent addstudent']
    [1,1,0],[1],[2],[3],[1]
    输出
    [null true, true, false, false]
    解释
    School System school System= rew Schoolsystem(1,1,0);/初始化有1个大班名额,1个中班名额,0个小班名额
    schoolsystem. addstudent(1)∥返回true,因为有1个剩余的大班名额
    school System. addstudent(2);/返回tue,因为有1个剩余的中班名额
    schodsyster. addstudent(3)返回 false,因为没有剩余的小班名额
    schod System. addstudent(1)返回 false,因为没有剩余的大班名额,唯一1个大班名额经被占据了
    需要实现的接口及代码主体参考
    /报名入学接口
    interface Isignupf
    打印輸出结果
    public vold printo;
    ∥检查是否有 stuType对应的班级名额
    ∥如果没有剩余名额,请返回 false,否则学生将报名进入该班级并返回true
    public boolean adcstudert (int stutype),
    解析命令行输入的参数(格式),如文摧述
    public static Iparams parse throws Exception
    interface Params
    ∥获取大班名额
    public int geteigo)
    ∥获取中班名额
    public int getmedium
    获取小班名额
    public int getsma
    ∥获取入学序列,例如[1223]表示依次报名入学一名大班学生,中班学生,中班学生,小班学生

img

  • 写回答

1条回答 默认 最新

  • 王大师王文峰 企业官方账号 2023-02-21 11:24
    关注

    望采纳

    public class Schoolsystem {
        private int big;
        private int medium;
        private int small;
        
        public Schoolsystem(int big, int medium, int small) {
            this.big = big;
            this.medium = medium;
            this.small = small;
        }
        
        public boolean addstudent(int stutype) {
            if (stutype == 1 && big > 0) {
                big--;
                return true;
            } else if (stutype == 2 && medium > 0) {
                medium--;
                return true;
            } else if (stutype == 3 && small > 0) {
                small--;
                return true;
            }
            return false;
        }
        
        public static Params parse(String input) throws Exception {
            String[] arr = input.split(",");
            int big = Integer.parseInt(arr[0]);
            int medium = Integer.parseInt(arr[1]);
            int small = Integer.parseInt(arr[2]);
            int[] stutype = new int[arr.length - 3];
            for (int i = 3; i < arr.length; i++) {
                stutype[i - 3] = Integer.parseInt(arr[i]);
            }
            return new Params(big, medium, small, stutype);
        }
        
        public void print() {
            System.out.print("[");
            for (int i = 0; i < params.getStutype().length; i++) {
                System.out.print(addstudent(params.getStutype()[i]) + " ");
            }
            System.out.println("]");
        }
        
        public static class Params {
            private int big;
            private int medium;
            private int small;
            private int[] stutype;
            
            public Params(int big, int medium, int small, int[] stutype) {
                this.big = big;
                this.medium = medium;
                this.small = small;
                this.stutype = stutype;
            }
            
            public int getBig() {
                return big;
            }
            
            public int getMedium() {
                return medium;
            }
            
            public int getSmall() {
                return small;
            }
            
            public int[] getStutype() {
                return stutype;
            }
        }
    }
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 3月2日
  • 已采纳回答 2月22日
  • 专家修改了标签 2月21日
  • 修改了问题 2月20日
  • 展开全部

悬赏问题

  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题