帮忙写一个简单的java小程序

来源:百度知道 编辑:UC知道 时间:2024/09/27 19:18:06
从命令行接受多个学生的成绩,找出并显示其中的最高分、最低分(需要考虑异常)。
要求:
 成绩的数据类型为整型。
 学生数自动根据命令行参数的个数判别。
 字符串转整型的方法为:int Integer.parseInt(字符串)
 异常:
没有参数:自动抛出ArrayIndexOutOfBoundsException
参数非整数:自动抛出NumberFormatException
成绩范围不在0-100分之间:主动抛出IllegalArgumentException
 可供参考的标识名:类名Score、最高分highScore、最低分lowScore
知道你强,帮忙写下,谢谢

import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;

public class Test {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
boolean flag = true;// 是否还输入
Student stu = null;
ArrayList al = new ArrayList();
byte[] by = new byte[20];//用来存成绩
int count = 0;
while (flag) {
stu = new Student();
try {
System.in.read(by,0,by.length);
stu.setStuId(count);
try{
stu.setStuScore(Integer.parseInt(new String(by).trim()));
}catch(NumberFormatException e){
e.printStackTrace();
System.out.println("成绩必须为整数!");
}

al.add(stu);
System.out.println("是否继续输入: (Y/N)");

char ch = (char) System.in.read();
if (ch == 'N' || ch == 'n')
flag = fals