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 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
2条回答 默认 最新
- kun_hello 2016-12-10 05:22关注
/** * student 类 */ 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 score(){ float f = chinese + math + english; System.out.println("总成绩为:" + f); } /** * 平均成绩 */ public void average(){ float f = chinese + math + english; System.out.println("平均成绩为:" + f/3); } /** * 计算三好学生 */ public void goodstudent(){ float f = (chinese + math + english)/3; if(f>90){ System.out.println("是三好学生"); }else{ System.out.println("不是"); } } public float getChinese() { return chinese; } public void setChinese(float chinese) { this.chinese = chinese; } public float getMath() { return math; } public void setMath(float math) { this.math = math; } public float getEnglish() { return english; } public void setEnglish(float english) { this.english = english; } }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报