实现 Schoolsystem类
望采纳
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;
}
}
}