1. 假设现在有本科生打算在毕业之后考研,考研的录取分数线为320,包含四门课程,政治、英语、数学、专业课程,学生的字段属性包含姓名、性别、专业、毕业院校等字段。
2. 首先利用集合类ArrayList生成一个具有N(由你自己通过键盘输入个数)个学生的集合,对学生按照要求的字段进行初始化。
3. 定义考研“录取”接口,该接口的主要功能是根据考试分数确定是否考生上线(总分达到要求,单科成绩不低于60分),最后根据录取情况输出参加考试的学生名单、考研上线的学生名单并输出各科考试成绩

解决方案 »

  1.   


    import java.util.ArrayList;
    import java.util.List;
    class Student {
    private String name;
    private String sex;

    private double politicsScore;
    private double englishScore;
    private double mathScore;
    private double majorScore;

    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 double getPoliticsScore() {
    return politicsScore;
    }
    public void setPoliticsScore(double politicsScore) {
    this.politicsScore = politicsScore;
    }
    public double getEnglishScore() {
    return englishScore;
    }
    public void setEnglishScore(double englishScore) {
    this.englishScore = englishScore;
    }
    public double getMathScore() {
    return mathScore;
    }
    public void setMathScore(double mathScore) {
    this.mathScore = mathScore;
    }
    public double getMajorScore() {
    return majorScore;
    }
    public void setMajorScore(double majorScore) {
    this.majorScore = majorScore;
    }


    }public class Test {
    private static final double CUTOFF_SCORE = 320; private static void addStudentsInfo(List<Student> stuList) {
    Student stuA = new Student();
    stuA.setName("学生A");
    stuA.setSex("男");
    stuA.setPoliticsScore(90.0);
    stuA.setEnglishScore(90.0);
    stuA.setMajorScore(90.0);
    stuA.setMathScore(90.0);
    stuList.add(stuA);

    Student stuB = new Student();
    stuB.setName("学生B");
    stuB.setSex("男");
    stuB.setPoliticsScore(10.0);
    stuB.setEnglishScore(10.0);
    stuB.setMajorScore(10.0);
    stuB.setMathScore(10.0);
    stuList.add(stuB);
    }

    public static void main(String[] args) {
    List<Student> stuList = new ArrayList<Student>();
    addStudentsInfo(stuList);

    System.out.println("参加考试的学生");
    System.out.println("------------------------------------");
    for(Student stu : stuList) {
    System.out.println(stu.getName() + "\t" + stu.getSex());
    }

    System.out.println("\n被录取的学生");
    System.out.println("姓名\t政治\t英语\t数学\t专业");
    System.out.println("------------------------------------");
    for(Student stu : stuList) {
    // 总分是否超过320
    boolean allReach = false;
    double scores = stu.getEnglishScore() + stu.getMajorScore() 
    + stu.getMathScore() + stu.getPoliticsScore();
    if(scores >= CUTOFF_SCORE) {
    allReach = true;
    }

    // 每门是否都及格
    boolean eachReach = (stu.getEnglishScore() > 60) 
    && (stu.getMajorScore() > 60) 
    && (stu.getMathScore() > 60) 
    && (stu.getPoliticsScore() > 60);

    if (allReach && eachReach) {
    System.out.println(stu.getName() + "\t" 
    + stu.getPoliticsScore() + "\t"
    + stu.getEnglishScore() + "\t"
    + stu.getMathScore() + "\t"
    + stu.getMajorScore());
    }

    }
    }}
    结果如下:参加考试的学生
    ------------------------------------
    学生A 男
    学生B 男被录取的学生
    姓名 政治 英语 数学 专业
    ------------------------------------
    学生A 90.0 90.0 90.0 90.0
      

  2.   

    楼上的挺全的了,就不添了。
    就是往list里面添加sutdent对象而已
      

  3.   

    2. 首先利用集合类ArrayList生成一个具有N(由你自己通过键盘输入个数)个学生的集合,对学生按照要求的字段进行初始化。
    要自己输入N阿?
      

  4.   

     public static void main(String[] args) {
           Scanner scan=new Scanner(System.in);
           String input = scan.toString();
           List<Student> stuList = new ArrayList<Student>(int i = Integer.parseInt(input););
           addStudentsInfo(stuList);
    加到里面你试试  我是新手
      

  5.   


    package com.bean.test;public class Student {
    private String name; private double politicsScore;
    private double englishScore;
    private double mathScore;
    private double majorScore; public String getName() {
    return name;
    } public void setName(String name) {
    this.name = name;
    } public double getPoliticsScore() {
    return politicsScore;
    } public void setPoliticsScore(double politicsScore) {
    this.politicsScore = politicsScore;
    } public double getEnglishScore() {
    return englishScore;
    } public void setEnglishScore(double englishScore) {
    this.englishScore = englishScore;
    } public double getMathScore() {
    return mathScore;
    } public void setMathScore(double mathScore) {
    this.mathScore = mathScore;
    } public double getMajorScore() {
    return majorScore;
    } public void setMajorScore(double majorScore) {
    this.majorScore = majorScore;
    }}package com.bean.test;import java.util.List;public interface Helper {
    public void calculate(List<Student> students);
    }
    package com.bean.test;import java.util.List;public class HelperImpl implements Helper { @Override
    public void calculate(List<Student> stuList) {
    System.out.println("参加考试的学生");
            System.out.println("------------------------------------");
            for(Student stu : stuList) {
                System.out.println(stu.getName() );
            }
             
            System.out.println("\n被录取的学生");
            System.out.println("姓名\t政治\t英语\t数学\t专业");
            System.out.println("------------------------------------");
            for(Student stu : stuList) {
                // 总分是否超过320
                boolean allReach = false;
                double scores = stu.getEnglishScore() + stu.getMajorScore() 
                    + stu.getMathScore() + stu.getPoliticsScore();
                if(scores >= 320) {
                    allReach = true;
                }
                 
                // 每门是否都及格
                boolean eachReach = (stu.getEnglishScore() > 60) 
                    && (stu.getMajorScore() > 60) 
                    && (stu.getMathScore() > 60) 
                    && (stu.getPoliticsScore() > 60);
                 
                if (allReach && eachReach) {
                    System.out.println(stu.getName() + "\t" 
                            + stu.getPoliticsScore() + "\t"
                            + stu.getEnglishScore() + "\t"
                            + stu.getMathScore() + "\t"
                            + stu.getMajorScore());
                }
                 
            }
    }}package com.bean.test;import java.util.ArrayList;
    import java.util.List;
    import java.util.Scanner;public class Main {
    public static void main(String[] args) {
    Helper helper = new HelperImpl();
    List<Student> sList = new ArrayList<Student>();
    // 输入
    int number = 0;
    Scanner scanner = new Scanner(System.in);
    number = scanner.nextInt();
    int count = 1;
    while (count <= number) {
    System.out.println("请输入第" + count + "位同学信息:姓名\t英语\t政治\t专业\t数学");
    Student student = new Student();
    student.setName(scanner.next());
    student.setEnglishScore(scanner.nextDouble());
    student.setPoliticsScore(scanner.nextDouble());
    student.setMajorScore(scanner.nextDouble());
    student.setMathScore(scanner.nextDouble());
    sList.add(student);
    count++;
    }
    helper.calculate(sList);

    }}
    2
    请输入第1位同学信息:姓名 英语 政治 专业 数学
    aa 60 58 100 80
    请输入第2位同学信息:姓名 英语 政治 专业 数学
    bb 70 80 120 80
    参加考试的学生
    ------------------------------------
    aa
    bb被录取的学生
    姓名 政治 英语 数学 专业
    ------------------------------------
    bb 80.0 70.0 80.0 120.0