用Java编写一程序

来源:百度知道 编辑:UC知道 时间:2024/06/04 18:25:03
用Java编写一程序,输入一个班学生的某门课程成绩。统计及格人数、不及格人数、平均分。为此设计一个异常类,当输入的成绩小于0分或大于100时,抛出异常,程序中捕捉这个异常,并做出相应的处理。

完整程序见下,记得采用啊:
import java.util.*;

class MinusException extends ArithmeticException {
public MinusException() {

}

public MinusException(String str) {
super(str);
}

}

class OverException extends ArithmeticException {
public OverException() {

}

public OverException(String str) {
super(str);
}

}

public class TestScore {
public static void judgescore(int i) throws MinusException, OverException {
if (i < 0)
throw new MinusException("分数不能为负数");
if (i > 100)
throw new OverException("分数超过100,过大!");
}

public static void main(String[] args) {
int array[] = { 0, 0 };
int turn = 1;
double total = 0;
Scanner input = new Scanner(System.in);
int score = 0;
System.out.println("请输入学生成绩,输入-1退出:");
System.out.print("请