Student Level

题目:

Implement a class Student, including the following attributes and methods:

Two public attributes name(string) and score(int).
A constructor expect a name as a parameter.
A method getLevel to get the level(char) of the student.

score - level table:
A: score >= 90
B: score >= 80 and < 90
C: score >= 60 and < 80
D: score < 60

分析:

解法:

public class Student {
    /**
     * Declare two public attributes name(string) and score(int).
     */
    // write your code here
    public String name;
    public int score;

    /**
     * Declare a constructor expect a name as a parameter.
     */
    // write your code here
    public Student(String name) {
        this.name = name;
    }

    /**
     * Declare a public method `getLevel` to get the level(char) of this student.
     */
    // write your code here
    public char getLevel() {
        char res;
        if (score >= 90) {
            res = 'A';
        } else if (score >= 80) {
            res = 'B';
        } else if (score >= 60) {
            res = 'C';
        } else {
            res= 'D';
        }
        return res;
    }
}

results matching ""

    No results matching ""