控制台:
姓名:张三3 考号:3 ,被录取
姓名:张三4 考号:4 ,被录取
学校类
public class School {
private int line;//录取分数 300分以上
public int getLine() {
return line;
}
public void setLine(int line) {
this.line = line;
}
}
学生类
public class Pupil {
private String name;//名字
private int id;//考号
private int total;//综合成绩
private int sport;//体育成绩
public Pupil(int id, int total, String name, int sport) {
this.id = id;
this.total = total;
this.name = name;
this.sport = sport;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getTotal() {
return total;
}
public void setTotal(int total) {
this.total = total;
}
public int getSport() {
return sport;
}
public void setSport(int sport) {
this.sport = sport;
}
}
主类
import java.util.ArrayList;
public class Main {
public static void main(String[] args) {
ArrayList<Pupil>pupilArrayList = new ArrayList<Pupil>();
Pupil p1 = new Pupil(1,300,"张三1",97);
Pupil p2 = new Pupil(2,295,"张三2",90);
Pupil p3 = new Pupil(3,308,"张三3",91);
Pupil p4 = new Pupil(4,310,"张三4",88);
pupilArrayList.add(p1);
pupilArrayList.add(p2);
pupilArrayList.add(p3);
pupilArrayList.add(p4);
School school = new School();
school.setLine(301);
luQu(pupilArrayList,school);
}
//录取的方法
private static void luQu(ArrayList<Pupil> pupils, School school) {
for (int i = 0; i < pupils.size(); i++) {
Boolean isLuQu = false;
Pupil p = pupils.get(i);
if (school.getLine() < p.getTotal()) {//综合成绩在录取分上
isLuQu = true;
} else if (p.getSport() > 96 && p.getTotal() > 300) {
isLuQu = true;
}
if(isLuQu){
System.out.println("姓名:"+p.getName()+" 考号:"+p.getId()+" ,被录取");
}
}
}
}
package com. company;
import java. util. Scanner;
public class Main {
public static void main(String[]args){
System. out. println("请选择想要的水果:"+
"1.苹果"+
"2.香蕉"+
"3.草莓"+
"4.桃子");
Scanner input=new Scanner(System. in);
int a =input. nextInt();
Vegetable b =new Vegetable();
b. jieguo(a);
}
}
class Vegetable{
private int a;
public void jieguo(int a){
if( a == 1) {
System. out. println("需要18元");
}
if(a == 2) {
System. out. println("需要10元");
}
i f( a = = 3) {
System. out. println("需要20元");
}
if(a == 4) {
System. out. println("需要16元");
}
}
}