2、编写满足下列要求的程序:
(1)为学生创建一个Student类,这个类成员变量包括:每个学生的姓名(String)、ID(int)、语文成绩(chinese)、数学成绩(math)、英语成绩(english);
定义构造方法Student(String name,int ID,float chinese,float math,float english),完成对象属性的初始化
定义成员方法:计算 3门课程的“总分”sum()、“平均分”avg()、“最高分”max()及“最低分”min()。
(2)创建主类Main,利用数组对象的概念创建5个学生, 其姓名、ID和成绩均随机指定。输出每名同学的姓名,ID,总分,平均分,最高分及最低分。(其中,float输出按照,小数点后2位输出)
运行结果长啥样,不太懂呀
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- 垂子帘 2021-11-26 19:30关注
public class Student {
public String name;
public int ID;
public int chinese;
public int math;
public int english;
public Student() {
}
public Student(String name, int ID, int chinese, int math, int english) {
this.name = name;
this.ID = ID;
this.chinese = chinese;
this.math = math;
this.english = english;
}
@Override
public String toString() {
return "Student{" +
"name='" + name + ''' +
", ID=" + ID +
", chinese=" + chinese +
", math=" + math +
", english=" + english +
'}';
}
public int getAdd(){
return this.chinese+this.math+this.english;
}
public static void main(String[] args) {
Student[] students = new Student[5];
students[0]=new Student("1",1,1,1,1);
students[1]=new Student("2",1,1,1,1);
students[2]=new Student("3",1,1,1,1);
students[3]=new Student("4",1,1,1,1);
students[4]=new Student("5",1,1,1,1);
for (Student s: students){
System.out.println(s.name+s.ID+s.chinese+s.math+s.english);
}
}
}如有帮助,望采纳,谢谢
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报 编辑记录
悬赏问题
- ¥100 set_link_state
- ¥15 虚幻5 UE美术毛发渲染
- ¥15 CVRP 图论 物流运输优化
- ¥15 Tableau online 嵌入ppt失败
- ¥100 支付宝网页转账系统不识别账号
- ¥15 基于单片机的靶位控制系统
- ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
- ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
- ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
- ¥15 手机接入宽带网线,如何释放宽带全部速度