如何用Java程序写一个简单的“学生成绩和班委信息管理”


package shiyan6;

class Student {
    
    private String num;  // 学号,用于唯一标识一个学生
    private String name;  // 学生的姓名
    private float mathScore;  // 学生数学课程的成绩
    private float EnglishScore;  // 学生英语课程的成绩
    private float javaScore;  // 学生 Java 课程的成绩

    public Student(String num, String name, float mathScore, float englishScore, float javaScore) {
 
        this.num = num;
        this.name = name;
        this.mathScore = mathScore;
        this.EnglishScore = englishScore;
        this.javaScore = javaScore;
    }

    public double sumScore() {
        return mathScore + EnglishScore + javaScore;
    }
    public double testScore() {
        return sumScore() / 3;
    }
    public String getNum() {
        return num;
    }
    public void setNum(String num) {
        this.num = num;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public float getMathScore() {
        return mathScore;
    }
    public void setMathScore(float mathScore) {
        this.mathScore = mathScore;
    }
    public float getEnglishScore() {
        return EnglishScore;
    }
    public void setEnglishScore(float englishScore) {
        this.EnglishScore = englishScore;
    }
    public float getJavaScore() {
        return javaScore;
    }
    public void setJavaScore(float javaScore) {
        this.javaScore = javaScore;
    }
}


class StudentBW extends Student {


    private String 团支书;  // 团支书的职位名称
    private String 学习委员;  // 学习委员的职位名称
    private String 班长;  // 班长的职位名称
   
    public StudentBW(String num, String name, String 团支书, String 学习委员, String 班长,
                     float mathScore, float englishScore, float javaScore) {

        super(num, name, mathScore, englishScore, javaScore);

        this.团支书 = 团支书;
        this. 学习委员 = 学习委员;
        this.班长 = 班长;        
        assignPosition();
    }


    private void assignPosition() {

        if (班长 != null && !班长.isEmpty()) {
            System.out.println("姓名:"+getName() + " 担任 " + 班长 + " 职位");
        }
       
        if (团支书 != null && !团支书.isEmpty()) {
            System.out.println("姓名:"+getName() + " 担任 " + 团支书 + " 职位");
        }

        if (学习委员 != null && !学习委员.isEmpty()) {
            System.out.println("姓名:"+getName() + " 担任 " + 学习委员 + " 职位");
        }
    }

 
    @Override
    public double testScore() {        
        return super.testScore() + 5;
    }
}


public class shiyan6 {
    public static void main(String args[]) {
        StudentBW studentBW = new StudentBW("220121", "智汇星辰", null, "团支书", null, 145, 150, 150);
        System.out.println("评测成绩:" + studentBW.testScore());    
        Student student = new Student("220120", "张三", 130, 120, 135);     
        System.out.println("学号:" + student.getNum());
        student.setNum("123");
        System.out.println("新的学号:" + student.getNum());
    }
}

你可能感兴趣的:(java,python,开发语言)