永发信息网

JAVA基础问题,新手上路

答案:1  悬赏:60  手机版
解决时间 2021-04-12 03:03
  • 提问者网友:骨子里的高雅
  • 2021-04-11 15:19

怎么在Graduate类中写一个方法用来判断学生是否达到录取分数线,所有类都已经写好了,只是不知道怎么样写主类里面的判断方法,JAVA起步,大家帮帮忙吧

class School{ //定义学校类,包含setScoreLine和getScoreLine方法
int scoreLine;
void setScoreLine(){
this.scoreLine = scoreLine;
}
void getScoreLine(){
System.out.println("The scoreLine is :" + scoreLine);
}
}
class Student{ //定义学生类
String name;
long id;
int intgretResult;
int sports;

public Student(String name,long id,int intgretResult,int sports){
System.out.println("姓名是"+name+" "+"考号是"+id+" "+"综合成绩是"+intgretResult+"体育成绩是"+sports);
}

void getIntgretResult(int intgretResult,int sports){
System.out.println("The intgretResult is"+intgretResult+" "+"sports is"+sports);
}
}

public class Graduate{ //定义Graduate类,用来实现输出学生信息,并且要判断学生是否被符合录取要求
public static void main(String args[]){
School sc = new School();
sc.scoreLine = 400;
sc.setScoreLine();
sc.getScoreLine();

Student S1 = new Student("幽助",1621011,200,80);
Student S2 = new Student("藏马",1621012,290,150);
Student S3 = new Student("飞影",1621013,659,150);
Student S4 = new Student("桑原",1621014,270,150);

怎样在这个类里面写判断方法呢?(判断条件,intgretResult(总体成绩)>scoreLine (分数线) 或者 sports(体育成绩)>96并且intgretResult>300)

我不太明白要怎么实现这个判断,如果有四个学生的话,怎么写呢?
}
}

最佳答案
  • 五星知识达人网友:拜訪者
  • 2021-04-11 16:49
class School { // 定义学校类,包含setScoreLine和getScoreLine方法
int scoreLine;

void setScoreLine(int scoreLine) {
this.scoreLine = scoreLine;
}

void getScoreLine() {
System.out.println("The scoreLine is :" + scoreLine);
}
}

class Student { // 定义学生类
String name;
long id;
int intgretResult;
int sports;

public Student(String name, long id, int intgretResult, int sports) {
this.name = name;
this.id = id;
this.intgretResult = intgretResult;
this.sports = sports;
System.out.println("姓名是" + name + " " + "考号是" + id + " " + "综合成绩是"
+ intgretResult + "体育成绩是" + sports);
}

void getIntgretResult(int intgretResult, int sports) {
System.out.println("The intgretResult is" + intgretResult + " "
+ "sports is" + sports);
}
}

public class Graduate { // 定义Graduate类,用来实现输出学生信息,并且要判断学生是否被符合录取要求
public static void main(String args[]) {
School sc = new School();
sc.setScoreLine(400);
sc.getScoreLine();

Student S1 = new Student("幽助", 1621011, 200, 80);
Student S2 = new Student("藏马", 1621012, 290, 150);
Student S3 = new Student("飞影", 1621013, 659, 150);
Student S4 = new Student("桑原", 1621014, 270, 150);

goSchool(S1, sc);
goSchool(S2, sc);
goSchool(S3, sc);
goSchool(S4, sc);
}

public static void goSchool(Student student, School school){
if((student.intgretResult > school.scoreLine) || (student.sports>96 && student.intgretResult > 300)){
System.out.println(student.name + "被录取!");
}else{
System.out.println(student.name + "没能录取!");
}
}
}

我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯