如何用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());
    }
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值