Java问题应该如何解答

根据UML类图,编写学生类Student。

    注意:

    (1)图中省略了数据域的get()和set()方法,编码的时候需要添加。

    (2)在各个属性的修改器(即get方法)内部,如果传入参数数值小于0分(即成绩为负值)时,则抛出一个异常(异常信息设置为“illegal grade”),但不在本函数内部处理,同时将属性置为0。

img


【试题输入输出】
编写测试类,从键盘输入学生的学号、姓名、三科成绩,按照如下样例,计算并输出学生的平均成绩和总成绩

img


public class TestStudent {

public static void main(String[] a){

    Scanner input = new Scanner(System.in);

    Student s1 = new Student();

    s1.setStuNo(input.nextInt());

    s1.setName(input.next());

    try{

        s1.setEnglish(input.nextInt());

    }catch(Exception e1){

        System.out.println(e1.getMessage());

    }

    try{

        s1.setComputer(input.nextInt());

    }catch(Exception e2){

        System.out.println(e2.getMessage());

    }

    try{

        s1.setMath(input.nextInt());

    }catch(Exception e3){

        System.out.println(e3.getMessage());

    }

    System.out.println(s1.toString());

}

}