qq_36732538 2016-12-09 09:32 采纳率: 0%
浏览 882

java一个小题目,求大神解答

1、创建一个Student,
包含的属性:
(1)name:String,私有
(2)id:String,私有
(3)chinese:float,私有
(4)math:float,私有
(5)english:float,私有
包含的方法:
(1)构造器方法:public Student():初始化姓名为“张三”,学号为“111111”;
(2)构造器方法:public Student(String name,String id);用参数初始化姓名、学号;
(3)对chinese、math、english属性的设定和获得方法;
(4)求总成绩的方法:public void score();
(5)求平均成绩的方法:public void average();
(6)计算三好学生的方法:public void goodstudent():要求:平均成绩是90分以上的同学为三好学生;
2、创建studentDemo类,该类完成的功能:
(1) 用自己的名字、学号创建一个学生类对象,语文、数学和英语成绩通过输入对话框输入,输入的范围设定在“1-100”之间,其他输入无效;
(2)要求打印:你的姓名、学号、语文、数学、语文成绩;
(3)输出你的总成绩、平均成绩;输出你是否被评为“三好学生”。

  • 写回答

1条回答 默认 最新

  • jasondyoung 2016-12-09 15:55
    关注

    public class Student{
    private String name;
    private String id;
    private float chinese;
    private float math;
    private float english;

    public Student(){
        this.name = "张三";
        this.id = "111111";
    }
    public Student(String name,String id){
        this.name = name;
        this.id = id; 
    }
    
    public void setChinese(float chinese){
        this.chinese = chinese;
    }
    
    public float getChinese(){
        return this.chinese;
    }
    
    public void setMath(float math){
        this.math = math;
    }
    
    public float getMath(){
        return this.math;
    }
    

    public void setEnglish(float english){
    this.english = english;
    }

    public float getEnglish(){
        return this.english;
    }
    
    public void score(){
        double score = this.chinese + this.math + this.english;
        System.out.println("总分为:" + score);
    }
    
    public void average()){
        double average = (this.chinese + this.math + this.english)/3;
        System.out.println("平均分为:" + average);
    }
    
    public void goodstudent(){
        double average = (this.chinese + this.math + this.english)/3;
        if(average >= 90){
            System.out.println(this.name+",该生是三好学生");
        }
    
    }
    

    }

    评论

报告相同问题?

悬赏问题

  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型