java 录取学生

java 录取学生,第1张

public class School {

private String name

private double line

public School(){}

public School(String name,double line) {

super()

this.name=name

this.line = line

}

public double getLine() {

return line

}

public void setLine(double line) {

this.line = line

}

public String getName() {

return name

}

public void setName(String name) {

this.name = name

}

}

public class Student {

private String id

private String name

private double total

private double sports

public Student(){

}

public Student(String id, String name, double total, double sports) {

super()

this.id = id

this.name = name

this.total = total

this.sports = sports

}

public String getId() {

return id

}

public void setId(String id) {

this.id = id

}

public String getName() {

return name

}

public void setName(String name) {

this.name = name

}

public double getTotal() {

return total

}

public void setTotal(double total) {

this.total = total

}

public double getSports() {

return sports

}

public void setSports(double sports) {

this.sports = sports

}

}

public class Pass {

public void status(School s,Student stu){

if(stu.getTotal()>=s.getLine()||(stu.getSports()>=96||stu.getTotal()>=300)){

System.out.println("学号为:"+stu.getId()+" "+"姓名为:"+stu.getName()+"的同学被"+s.getName()+"录取,该学校的录取分数线为:"+s.getLine())

}else{

System.out.println("学号为:"+stu.getId()+" "+"姓名为:"+stu.getName()+"的同学没有被"+s.getName()+"录取,该学校的录取分数线为:"+s.getLine())

}

}

public static void main(String[] args){

School school1=new School("清华大学",680)

School school2=new School("北京大学",660)

Student stu1=new Student("2012121201","小红",690,80)

Student stu2=new Student("2012121201","小明",650,80)

Student stu3=new Student("2012121201","张三",670,80)

Student stu4=new Student("2012121201","李四",640,80)

Pass p=new Pass()

p.status(school1, stu1)

p.status(school1, stu2)

p.status(school2, stu3)

p.status(school2, stu4)

}

}

运行结果为:

学号为:2012121201 姓名为:小红的同学被清华大学录取,该学校的录取分数线为:680.0

学号为:2012121201 姓名为:小明的同学被清华大学录取,该学校的录取分数线为:680.0

学号为:2012121201 姓名为:张三的同学被北京大学录取,该学校的录取分数线为:660.0

学号为:2012121201 姓名为:李四的同学被北京大学录取,该学校的录取分数线为:660.0

import java.util.Scanner

public class App

{

public static void main(String[] args)

{

final String[][] strstrs=

{

{"民办本科","350 分"},{"艺术类本科","290 分"},

{"体育类本科","280 分"},{"二本","445 分"},

{"一本","555 分"}

}

final String msg="请输入要查询的录取分数线(比如民办本科、"+

"艺术类本科、体育类本科、二本、一本):"

String input

boolean invalidate=true

Scanner sc=new Scanner(System.in)

System.out.print(msg)

input=sc.nextLine().trim()

for(String[] strs : strstrs)

{

if(strs[0].equals(input))

{

System.out.printf("%s录取分数线:%s%n",input,strs[1])

invalidate=false

break

}

}

if(invalidate)

System.out.println("没有相关查询的录取分数线")

sc.close()

}

}

public class Admission {

public static void isAdmission(School sch, Student[] stu) {

System.out.println("录取分数线 --" + sch.getLine())

for (int i = 0i <stu.lengthi++) {

if (stu[i].getTotal() >= 300 &&stu[i].getSports() >= 96

&&stu[i].getTotal() >= sch.getLine()) {

System.out.println("您被录取了,您的成绩 --" + stu[i])

}

}

}

public static void main(String[] args) {

School sch = new School()

sch.setLine(510)

Student s1 = new Student()

s1.setId("20090811")

s1.setName("s1")

s1.setSports(95)

s1.setTotal(600)

Student s2 = new Student()

s2.setId("20090812")

s2.setName("s2")

s2.setSports(99)

s2.setTotal(650)

Student s3 = new Student()

s3.setId("20090813")

s3.setName("s3")

s3.setSports(96)

s3.setTotal(509)

Student s4 = new Student()

s4.setId("20090814")

s4.setName("s4")

s4.setSports(97)

s4.setTotal(511)

Student s5 = new Student()

s5.setId("20090815")

s5.setName("s5")

s5.setSports(97)

s5.setTotal(201)

Student[] stcon = { s1, s2, s3, s4, s5 }

isAdmission(sch,stcon)

}

}

class School {

private double line

public double getLine() {

return line

}

public void setLine(double line) {

this.line = line

}

}

class Student {

private String id

private String name

private double total

private double sports

public String getId() {

return id

}

public void setId(String id) {

this.id = id

}

public String getName() {

return name

}

public void setName(String name) {

this.name = name

}

public double getTotal() {

return total

}

public void setTotal(double total) {

this.total = total

}

public double getSports() {

return sports

}

public void setSports(double sports) {

this.sports = sports

}

@Override

public String toString() {

StringBuffer stb = new StringBuffer()

stb.append("姓名: " + this.getName() + " 学号:" + this.getId() + " 综合成绩:"

+ this.getTotal() + " 体育成绩: " + this.getSports())

return stb.toString()

}

结果:

录取分数线 --510.0

您被录取了,您的成绩 --姓名: s2 学号:20090812 综合成绩:650.0 体育成绩: 99.0

您被录取了,您的成绩 --姓名: s4 学号:20090814 综合成绩:511.0 体育成绩: 97.0


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/11294363.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-15
下一篇 2023-05-15

发表评论

登录后才能评论

评论列表(0条)

保存