少年 15分太少 …… 不过几天没人帮你了 我帮你下吧
class Student {
private int yuwen;
private int shuxue;
private int yinyu;
private int xuehao;
private String name;
public int getYuwen() {
return yuwen;
}
public void setYuwen(int yuwen) {
this.yuwen = yuwen;
}
public int getShuxue() {
return shuxue;
}
public void setShuxue(int shuxue) {
this.shuxue = shuxue;
}
public int getYinyu() {
return yinyu;
}
public void setYinyu(int yinyu) {
this.yinyu = yinyu;
}
public int getXuehao() {
return xuehao;
}
public void setXuehao(int xuehao) {
this.xuehao = xuehao;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return "Student [yuwen=" + yuwen + ", shuxue=" + shuxue + ", yinyu=" + yinyu + ", xuehao=" + xuehao + ", name="
+ name + "]";
}
public Student(String name,int xuehao,int yuwen, int shuxue, int yinyu ) {
super();
this.yuwen = yuwen;
this.shuxue = shuxue;
this.yinyu = yinyu;
this.xuehao = xuehao;
this.name = name;
}
public int pinjun(int yuwen, int shuxue, int yinyu){
return (yuwen+shuxue+yinyu)/3;
}
}
class Test {
public static void main(String args[]) throws IOException {
ArrayList<Student> al = new ArrayList<>();
Scanner sc = new Scanner(System.in);
FileWriter fw = new FileWriter("D:\\a.txt");
while(al.size()<6){
String input = sc.nextLine();
System.out.println("请输入学生 格式为:姓名+空格+学号+空格+语文成绩+空格+数学成绩+空格+英语成绩");
String [] xx = input.split(" ");
try {
al.add(new Student(xx[0],Integer.parseInt(xx[1]),Integer.parseInt(xx[2]),Integer.parseInt(xx[3]),Integer.parseInt(xx[4])));
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
System.out.println("格式错误");
}
}
int pinjun=0;
for (Student student : al) {
pinjun+=student.pinjun(student.getYuwen(), student.getShuxue(), student.getYinyu())/6;
}
for (Student student : al) {
if(student.pinjun(student.getYuwen(), student.getShuxue(), student.getYinyu())<pinjun){
fw.write(student.toString());
}
}
}
}
|