<1>一个学校类,其中包含成员变量“录取分数线”和对该变量值进行设置和获取的方法。
<2>一个学生类,成员变量有“姓名”,“考号”,“综合成绩”,“体育成绩”。它还有获取学生的综合成绩和体育成绩的方法。
<3>一个录取类,它的一个方法用于判断学生是否符合条件。其中录取条件是:综合成绩在录取分数线之上,或体育成绩在96分以上并且综合成绩大于300分。该类中的main()方法建立若干个学生对象,并对符合录取条件的学生,输出其相关信息及“被录取”字样。
   对于这个程序,我弄不清这些类之间是如何建立联系的,凭着感觉编出如下程序,感觉是漏洞百出,想从课本上找答案,可是翻了几遍也没有和这个程序相似的,真的让我很郁闷,希望哪位不嫌弃,教一下在下,在此先谢了!!!!!!
  
package test4;/**
 *
 * @author Administrator
 */
public class student {
       public student(String nam,String num,int zsc,int psc){
            name=nam;
            number=num;
            zscore=zsc;
            pscore=psc;
                     
    }
     public int get_zscore(){
         return zscore;
     }
     public int pscore(){
          return pscore;
     }
     protected String name;
     protected String number;
     protected static int zscore;
     protected int pscore;}   
   package test4;/**
 *
 * @author Administrator
 */
public class school {
  public static int pass_line;
 
    public static int set_line()
    {   pass_line=360;
        return pass_line;
               
    }
  
    }    
     package test4;   public class luqu {    /**
     * @param args the command line arguments
     */
    public String qualification(){
        
         if (student.zscore >student.pass_line)
             System.out.println("录取"+student.name+student.number+student.zscore+student.pscore);
    }
    
    
    public static void main(String[] args) {
        // TODO code application logic here
        student student1;
        student1=new student("aaa","11",368,78);
        student1.qualification();}

解决方案 »

  1.   

    luqu里面 应该有 Student集合的实例变量  这样就可以解决了public class Luqu { 
         private List<Student> students;
        /** 
         * @param args the command line arguments 
         */ 
        public Luqu(){
         students = new LinkedList<Student>();
        }     public add(Student s){
         students.add(s);
        }
        public void qualification(){ 
             for(Student student : Students)
             if (student.zscore >School.pass_line) 
                 System.out.println("录取"+student.name+student.number+student.zscore+student.pscore); 
        } 
         
         
        public static void main(String[] args) { 
            // TODO code application logic here 
            Luqu l = new Luqu();
            student student1; 
            student1=new student("aaa","11",368,78); 
            l.add(l);
            l.qualification(); } PS:  在你的基础上改成这样就可以实现功能了。
          建议修改一下你的类的设计,这个设计不太好。
      

  2.   


       public class luqu {     /** 
         * @param args the command line arguments 
         */ 
        public static void   qualification(student st,school sh){ 
             
             if (st.zscore >sh.pass_line) 
                 System.out.println("录取"+st.name+st.number+st.zscore+st.pscore); 
        } 
         
         
        public static void main(String[] args) { 
            // TODO code application logic here 
            student student1; 
            student1=new student("aaa","11",368,78); 
            luqu.qualification(student1, new school());
        }} 
    //其他2个类不变,luqu这个类这样些一下看 
      

  3.   

    student1.qualification();该成------>new luqu().qualification(student1);
    外加把方法qualification()改成传参的qualification(Student student)
      

  4.   


    package net.csdn;public class Student { private String number; private String name; private int zscore; private int pscore; public Student(String number, String name, int zscore, int pscore) {
    this.name = name;
    this.number = number;
    this.zscore = zscore;
    this.pscore = pscore;
    } public String getName() {
    return name;
    } public void setName(String name) {
    this.name = name;
    } public String getNumber() {
    return number;
    } public void setNumber(String number) {
    this.number = number;
    } public int getPscore() {
    return pscore;
    } public void setPscore(int pscore) {
    this.pscore = pscore;
    } public int getZscore() {
    return zscore;
    } public void setZscore(int zscore) {
    this.zscore = zscore;
    }

    @Override
    public String toString(){
    return "姓名:"+this.name+"学号:"+this.number+"体育:"+this.pscore+"总分:"+this.zscore;
    }}
    package net.csdn;public class School { private int pass_line; public School(int passLine) {
    this.pass_line = passLine;
    } public int getPass_line() {
    return pass_line;
    } public void setPass_line(int pass_line) {
    this.pass_line = pass_line;
    }
    }package net.csdn;import java.util.List;public class Luqu { private final static int P_SCORE = 96; private final static int Z_SCORE = 300; private School school; private List<Student> list; public Luqu(School school, List<Student> list) {
    this.school = school;
    this.list = list;
    } private Student qualification(Student student, School school) { if (student.getZscore() > school.getPass_line()
    || (student.getPscore() > P_SCORE && student.getZscore() > Z_SCORE))
    return student;
    return null;
    } public String matriculateList() {
    StringBuffer sb = new StringBuffer();
    for (Student student : list) {
    if (this.qualification(student, school) != null)
    sb.append(student.toString()).append("\n");
    }
    return sb.toString();
    } public List<Student> getList() {
    return list;
    } public void setList(List<Student> list) {
    this.list = list;
    } public School getSchool() {
    return school;
    } public void setSchool(School school) {
    this.school = school;
    }}
    package net.csdn;import java.util.ArrayList;
    import java.util.List;public class Test { public static void main(String[] args) { School school = new School(100);
    Student student1=new Student("21","xx",200,60); 
    Student student2=new Student("22","xxx",90,60); 
    Student student3=new Student("23","xxxx",400,100);
    List<Student> list = new ArrayList<Student>();
    list.add(student1);
    list.add(student2);
    list.add(student3);
    Luqu lq = new Luqu(school,list);
    System.out.println("录取情况:\n"+lq.matriculateList());
    }}
    录取情况:
    姓名:xx学号:21体育:60总分:200
    姓名:xxxx学号:23体育:100总分:400