1 Star 0 Fork 3

沈帆 / 刘昇-202110098196

forked from sheng7963 / 刘昇-202110098196 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
SchoolSystem.java 2.55 KB
一键复制 编辑 原始数据 按行查看 历史
freesoul-lonelyspirit 提交于 2022-10-10 22:30 . 修改刘昇的代码文件
package version;
import java.util.ArrayList;
import java.util.Scanner;
public class SchoolSystem implements ISignUp //刘昇爸爸是陈淑创
{
//合并分支
Integer big;
Integer medium;
Integer small;
SchoolSystem (Integer big, Integer medium, Integer small)
{
this.big=big;
this.medium=medium;
this.small=small;
}
public static void main(String[] args) throws Exception
{
IParams params = ISignUp.parse();
SchoolSystem sc = new SchoolSystem (params.getBig(), params.getMedium(),params.getSmall());
ArrayList<Integer> plan =params.getPlanSignUp();
ArrayList <Boolean>whether=new ArrayList();
for (int i = 0; i < plan.size(); i++)
{
whether.add( sc.addStudent (plan.get(i)));
}
sc. print(whether);
}
public void print (ArrayList<Boolean> whether)
{
System.out.println(whether);
}
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;
}
else
return false;
}
}
//报名入学接口
interface ISignUp
{
// 打印输出结果
public void print(ArrayList<Boolean> plan);
// 检查是否有 stuType对应的班级名额
// 如果没有剩余名额,请返回 false ,否则学生将报名进入该班级并返回 true
public boolean addStudent (int stuType);
// 解析命令行输入的参数(格式),如文档描述
public static IParams parse() throws Exception
{
Scanner sc=new Scanner(System.in);
System.out.print("请输入每种班级的剩余名额:");
Integer big=sc.nextInt();
Integer medium=sc.nextInt();
Integer small=sc.nextInt();
ArrayList <Integer> list=new ArrayList();
System.out.print("请输入需要进入的班级:");
//输入报名班级次序,4次
for(int i=1;i<5;i++)
{
list.add(sc.nextInt());
}
//SchoolSystem scs=new SchoolSystem(big,medium,small);
return new IParams()
{
public int getBig()
{
return big;
}
public int getMedium()
{
return medium;
}
public int getSmall()
{
return small;
}
public ArrayList<Integer> getPlanSignUp()
{
return list;
}
};
};
}
interface IParams
{
// 获取大班名额
public int getBig();
// 获取中班名额
public int getMedium();
// 获取小班名额
public int getSmall();
// 获取入学序列,例如 [1 2 2 3] 表示 依次报名入学一名大班学生,中班学生,中班学生,小班学生
public ArrayList<Integer> getPlanSignUp ();
}
1
https://gitee.com/sehnfan/liu-sheng-202110098196.git
git@gitee.com:sehnfan/liu-sheng-202110098196.git
sehnfan
liu-sheng-202110098196
刘昇-202110098196
master

搜索帮助