handsom5382 2021-10-08 11:45 采纳率: 33.3%
浏览 121
已结题

java程序设计设计学生累

设计一个学生类,包含学生的姓名、学号、课程数(不可修改)、各门课程的成绩;可以获取学生的学号,但不能修改;可以获取和修改姓名;可以输入和读取成绩;可以获得学生的平均成绩。
写出具体类的成员方法和函数定义,并写出测试的main函数。

  • 写回答

1条回答 默认 最新

  • CSDN专家-sinJack 2021-10-08 11:49
    关注
    public class Student {
        private String name;
        private String sno;
        private Integer cnum;
        private Integer english;
        private Integer math;
        private Integer chinese;
    
        public Student(String name, String sno, Integer cnum, Integer english, Integer math, Integer chinese) {
            this.name = name;
            this.sno = sno;
            this.cnum = cnum;
            this.english = english;
            this.math = math;
            this.chinese = chinese;
        }
    
        public void setName(String name) {
            this.name = name;
        }
    
        public void setEnglish(Integer english) {
            this.english = english;
        }
    
        public void setMath(Integer math) {
            this.math = math;
        }
    
        public void setChinese(Integer chinese) {
            this.chinese = chinese;
        }
    
        public String getName() {
            return name;
        }
    
        public String getSno() {
            return sno;
        }
    
        public Integer getEnglish() {
            return english;
        }
    
        public Integer getMath() {
            return math;
        }
    
        public Integer getChinese() {
            return chinese;
        }
    
        public double avg(){
            return (getEnglish()+getMath()+getChinese())/3.0;
        }
    
        @Override
        public String toString() {
            return "Student{" +
                    "name='" + name + '\'' +
                    ", sno='" + sno + '\'' +
                    ", cnum=" + cnum +
                    ", english=" + english +
                    ", math=" + math +
                    ", chinese=" + chinese +
                    '}';
        }
    
        public static void main(String[] args) {
            Student student=new Student("小白","1001",3,88,99,66);
            System.out.println(student);
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 10月18日
  • 已采纳回答 10月10日
  • 创建了问题 10月8日

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效