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)输出你的总成绩、平均成绩;输出你是否被评为“三好学生”。
java一个小题目,求大神解答
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
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+",该生是三好学生"); } }
}
解决 无用评论 打赏 举报