初学者,求教。

xue333yuan 2012-03-19 11:10:08
定义一个表示学生的类,类包括表示学生的学号,姓名,性别,年龄和3门课程成绩的信息数据及用来获得和设置学号,姓名 性别 年龄和3门课程成绩的方法。创建TESTSTudent,生成5个学生对象,计算3门课程的平均成绩,以及某门课程的最高分和最低分。


求教怎么定义 3门课程的最高分最低分的方法。
...全文
38 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
dryZeng 2012-03-19
  • 打赏
  • 举报
回复
你是想用代码还是想用sql语句?
安特矮油 2012-03-19
  • 打赏
  • 举报
回复
以后这种问题自己多想想吧。

package com.study;


public class Student {

private int no;
private String name;
private String sex;
private int age;
private double score1;
private double score2;
private double score3;

public double getAvgScore(){
return score1*score2*score3/3;
}

public Student(int no, String name, String sex, int age, double score1,
double score2, double score3) {
super();
this.no = no;
this.name = name;
this.sex = sex;
this.age = age;
this.score1 = score1;
this.score2 = score2;
this.score3 = score3;
}
public int getNo() {
return no;
}
public void setNo(int no) {
this.no = no;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public double getScore1() {
return score1;
}
public void setScore1(double score1) {
this.score1 = score1;
}
public double getScore2() {
return score2;
}
public void setScore2(double score2) {
this.score2 = score2;
}
public double getScore3() {
return score3;
}
public void setScore3(double score3) {
this.score3 = score3;
}

}



package com.study;


public class Test {
public static void main(String[] args) {
Student s1 = new Student(1,"张1","男",11,80,80,80);
Student s2 = new Student(2,"张2","男",12,78,66,90);
Student s3 = new Student(3,"张3","男",11,55,44,50);
Student s4 = new Student(4,"张4","男",13,88,92,99);
Student s5 = new Student(5,"张5","男",11,75,86,22);
Student[] ss = new Student[]{s1,s2,s3,s4,s5};
System.out.println("===========================================");
double maxScore1 = -1;
double maxScore2 = -1;
double maxScore3 = -1;
double minScore1 = Double.MAX_VALUE;
double minScore2 = Double.MAX_VALUE;
double minScore3 = Double.MAX_VALUE;
for(Student s : ss){
System.out.println(s.getName() + "的平均成绩为:" + s.getAvgScore());
if(maxScore1 <= s.getScore1()){
maxScore1 = s.getScore1();
}
if(minScore1 >= s.getScore1()){
minScore1 = s.getScore1();
}

if(maxScore2 <= s.getScore2()){
maxScore2 = s.getScore2();
}
if(minScore2 >= s.getScore2()){
minScore2 = s.getScore2();
}

if(maxScore3 <= s.getScore3()){
maxScore3 = s.getScore3();
}
if(minScore3 >= s.getScore3()){
minScore3 = s.getScore3();
}
}
System.out.println("===========================================");
System.out.println("score1最高分为:" + maxScore1);
System.out.println("score2最高分为:" + maxScore2);
System.out.println("score3最高分为:" + maxScore3);
System.out.println("===========================================");
System.out.println("score1最低分为:" + minScore1);
System.out.println("score2最低分为:" + minScore2);
System.out.println("score3最低分为:" + minScore3);
}
}

xue333yuan 2012-03-19
  • 打赏
  • 举报
回复
不是求某学生的3门成绩的最高和最低。
是求5个学生中的最高和最低。
貌似用数组去求。
弄不明白。高手出现吧。

50,528

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧