第一题
1.建一个学校类, 包括成员变量  录取分数线(scoreline),并对其进行设置和获取的方法。
2.建一个学生类,包括考生姓名(name),考号(id) 综合成绩(intgretResult) 体育成绩(sport)
并分别对 综合成绩,体育成绩进行设置和获取的方法。
3.建一个录取类,它判断学生是否 符合录取条件:综合成绩>录取分数线,或者 综合成绩>300并且体育成绩>96,以上2种条件为被录取。否则不录取。
4.用main()方法建立若干个对象,对符合录取条件的学生输出“录取”;
第二题
(1)设计一个表示二维平面空间上点的类point,包含有表示坐标位置的protected类型的成员变量X和Y,并写出设置和获取X,Y的Public的方法。
(2)设计一个表示二维平面上圆的类Circle 它继承自类point。还包含有表示圆半径protected类型的成员变量Radius,并写出设置和获取Radius的值的Public方法,计算圆面积的Public方法。
(3)设计一个表示圆柱体的Cylinder的类。它继承类Circle ,还有表示圆柱体高的protected类型的成员变量height,并写出设置和获取Radius的值的Public的方法。计算圆柱体体积的方法
(4)建若干个Cylinder对象,输出: 轴心坐标 ,半径,高以及体积的值。要求:1.子类的构造方法调用父类的构造方法,对父类中的成员变量初始化。     2.写的类包含无参数和 有参数的构造方法。构造方法用与成员变量的初始化希望大家帮助哈,我一般都是在线等待的....

解决方案 »

  1.   

    SchoolAndStudentTest.java
    ====================================================================
    public class SchoolAndStudentTest {
        /** Creates a new instance of SchoolAndStudentTest */
        public SchoolAndStudentTest() {
        }
        
        /**
         * 用来测试的main函数
         */
        public static void main(String[] args){
            //建立三个学生对象
            Student[] students = new Student[3];
            students[0] = new Student("张三","A1001");
            students[0].setIntgretResult(405);
            students[0].setSport(50);
            students[1] = new Student("李四","A1002");
            students[1].setIntgretResult(305);
            students[1].setSport(97);
            students[2] = new Student("王五","A1003");
            students[2].setIntgretResult(350);
            students[2].setSport(95);
            //建立学校对象
            School school = new School();
            //设置录取分数线
            school.setScoreline(400);
            //循环遍历所有的学生, 输出录取情况
            for(int i = 0;i < students.length;i++){
                if( school.matriculate(students[i].getIntgretResult(),students[i].getSport())){
                    System.out.println(students[i].getName() + "被录取了");
                }
                else{
                    System.out.println(students[i].getName() + "没有被录取");
                }
            }
        }
    }
    /**
     *学校类
     */
    class School {
        private int scoreline;
        public School(){
            
        }
        public School(int scoreline){
            this.scoreline = scoreline;
        }
        public void setScoreline(int scoreline){
            this.scoreline = scoreline;
        }
        
        public int getScoreline(){
            return this.scoreline;
        }
        
        //录取函数,录取返回true,否则返回false
        public boolean matriculate(int  score,int sport){
            boolean pass = false;
            if(score > this.scoreline || ((score > 300) && (sport > 96)) ){
                pass = true;
            }
            return pass;
        }
        
    }/**
     *学生类
     */
    class Student {
        private String name;
        private String id;
        private int intgretResult;
        private int sport;
        public Student(){
            
        }
        
        public Student(String name,String id){
            this.name = name;
            this.id = id;
        }
        public String getName(){
            return this.name;
        }
        
        public void setIntgretResult(int intgretResult){
            this.intgretResult = intgretResult;
        }
        
        public int getIntgretResult(){
            return this.intgretResult;
        }
        
        public void setSport(int sport){
            this.sport = sport;
        }
        
        public int getSport(){
            return this.sport;
        }
    }----------------------------------------------------------------
     hoho,自己写了个,权当打打字,练练手
      

  2.   

    class Students
    {
         private String name;
         private int id;
         private double intgretResult;
         private int sport;
       public Students(String name,int id,double intgretResult,int sport)
       {
                this.name = name;
                this.id = id;
                this.intgretResult = intgretResult;
                this.sport = sport;
        }    public void setintgretResult(double zong)
        {
                   this.intgretResult = zong;
         }
       
         public double getintgretResult()
         {
                   return this.intgretResult;
          }     public void setSport(int fen)
         {
                 this.sport = fen;
          }
          
          public int getSport()
          {
                return this.sport;
           }
    }
      就写一个,自己多少写点吧
      

  3.   

    CylinderTest.java
    ================================================================
    public class CylinderTest {  
        /** Creates a new instance of CylinderTest */
        public CylinderTest() {
        }
        /**
         *测试的main函数
         */
        public static void main(String[] args){
            Cylinder[] cylinders = new Cylinder[3];
            cylinders[0] = new Cylinder(3,5,6,10);
            cylinders[1] = new Cylinder(2,2,7,12);
            cylinders[2] = new Cylinder(10,10,20,30.5);
            for(int i = 0;i < cylinders.length;i++){
                System.out.println("轴心坐标 :(" + cylinders[i].getX() + "," + cylinders[i].getY() + ")");
                System.out.println("半径:" + cylinders[i].getRadius());
                System.out.println("高:" + cylinders[i].getHeight());
                System.out.println("圆的面积:" + cylinders[i].calculateArea(cylinders[i].getRadius()));
                System.out.println("圆柱体的体积:" + cylinders[i].calculateVolumn(cylinders[i].getRadius(),cylinders[i].getHeight()));
            }
        }
        
    }/**
     *Point类
     */
    class Point{
        protected int x;
        protected int y;
        public Point(int x,int y){
            this.x = x;
            this.y = y;
        }
        public void setX(int x){
            this.x  = x;
        }
        public int getX(){
            return this.x;
        }
        
        public void setY(int y ){
            this.y = y;
        }
        
        public int getY(){
            return this.y;
        }
    }
    /**
     *Circle 类
     */
    class Circle extends Point{
        protected double radius;
        public Circle(int x,int y,double radius){
            super(x,y);
            this.radius = radius;
        }
        
        public void setRadius(double redius){
            this.radius = radius;
        }
        public double getRadius(){
            return this.radius;
        }
        /**
         *计算圆的面积
         */
        public double calculateArea(double radius){
            double area = Math.PI * radius * radius;
            return area;
        }
    }
    /**
     *Cylinder类
     */
    class Cylinder extends Circle{
        protected double height;
        public Cylinder(int x,int y,double radius,double height){
            super(x,y,radius);
            this.height = height;
        }
        public void setHeight(double height){
            this.height = height;
        }
        public double getHeight(){
            return this.height;
        }
        public double getRadius(){
            return this.radius;
        }
        public void setRadius(double radius){
            this.radius = radius;
        }
        /**
         *计算圆柱体的体积
         */
        public double calculateVolumn(double radius,double height){
            double volumn =  super.calculateArea(radius) * height;
            return volumn;
        }
        
    }
      

  4.   

    public class  School
    {
    private float scoreline;
    public School()
    {
    this.scoreline=0.0f;
    }
    public School(float scoreline)
    {
    this.scoreline=scoreline;
    }
    public float getScoreline()
    {
    return scoreline;
    }
    public void setScoreline(float scoreline)
    {
    this.scoreline=scoreline;
    }
    }
      

  5.   

    public class  Student
    {
    private String id;
    private String name;
    private float intgretResult;
    private float sport;
    public Student()
    {
    this.id="null";
    this.name="null";
    this.intgretResult=0.0f;
    this.sport=0.0f;
    }
    public Student(String id,String name)
    {
    this.id=id;
    this.name=name;
    }
    public Student(String id,String name,float intgretResult,float sport)
    {
    this.id=id;
    this.name=name;
    this.intgretResult=intgretResult;
    this.sport=sport;
    }
    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 float getIntgretResult()
    {
    return intgretResult;
    }
    public void setIntgretResult(float intgretResult)
    {
    this.intgretResult=intgretResult;
    }
    public float getSport()
    {
    return sport;
    }
    public void setSport(float sport)
    {
    this.sport=sport;
    }
    }
      

  6.   

    public class  Matriculate
    {
    private School school;
    private java.util.List alternateStudents;
    public Matriculate(School school,java.util.List alternateStudents)
    {
    this.school=school;
    this.alternateStudents=alternateStudents;
    }
    public void culate()
    {
    System.out.println("录取条件为:综合成绩大于录取分数线或者综合成绩>300并且体育成绩>96");
    java.util.Iterator i=alternateStudents.iterator();
    System.out.printf("考生ID|考生名称|综合成绩|体育成绩|录取分数线|录取结果\n");
    while(i.hasNext())
    {
    Student s=(Student)i.next();
    if(opinion(s))
    {
    //录取
    System.out.printf("%6s|%6s|%8s|%8s|%10s|%4s",s.getId(),s.getName(),String.valueOf(s.getIntgretResult()),String.valueOf(s.getSport()),String.valueOf(school.getScoreline()),"录取");
    }
    else
    {
    //未录取
    System.out.printf("%6s|%6s|%8s|%8s|%10s|%4s",s.getId(),s.getName(),String.valueOf(s.getIntgretResult()),String.valueOf(s.getSport()),String.valueOf(school.getScoreline()),"未录取");
    }
    System.out.println();
    }
    }
    private boolean opinion(Student student)
    {
    boolean isOpinion=false;
    if(student.getIntgretResult()>school.getScoreline())//综合成绩大于录取分数线
    {
    isOpinion=true;
    }
    else if((student.getIntgretResult()>300)&&(student.getSport()>96))//综合成绩>300并且体育成绩>96
    {
    isOpinion=true;
    }
    return isOpinion;
    }
    public static void main(String[] args)
    {
    School school=new School(450.0f);
    java.util.List list=new java.util.ArrayList();
    Student s1=new Student("001","张三",510.5f,68.0f);
    Student s2=new Student("002","李四",498.6f,80.2f);
    Student s3=new Student("003","王五",390.0f,97.4f);
    Student s4=new Student("004","赵六",330.0f,94.0f);
    Student s5=new Student("005","魏七",280.5f,99.0f);
    Student s6=new Student("006","孙八",296.0f,89.0f);
    list.add(s1);
    list.add(s2);
    list.add(s3);
    list.add(s4);
    list.add(s5);
    list.add(s6);
    Matriculate m=new Matriculate(school,list);
    m.culate();
    }
    }
      

  7.   

    public class  Point
    {
    protected int x;
    protected int y;
    public Point()
    {
    x=0;
    y=0;
    }
    public Point(int x,int y)
    {
    this.x=x;
    this.y=y;
    }
    public int getX()
    {
    return x;
    }
    public int getY()
    {
    return y;
    }
    public void setX(int x)
    {
    this.x=x;
    }
    public void setY(int y)
    {
    this.y=y;
    }
    }
      

  8.   

    public class Circle extends Point
    {
    protected float radius;
    public Circle()
    {
    super();
    radius=0;
    }
    public Circle(int x,int y,float radius)
    {
    super(x,y);
    this.radius=radius;
    }
    public float getRadius()
    {
    return radius;
    }
    public void setRadius(float radius)
    {
    this.radius=radius;
    }
    public double calculateArae()
    {
    return Math.PI*radius*radius;
    }
    }
      

  9.   

    public class Cylinder extends Circle 
    {
    protected float height;
    public Cylinder()
    {
    super();
    height=0.0f;
    }
    public Cylinder(int x,int y,float radius,float height)
    {
    super(x,y,radius);
    this.height=height;
    }
    public float getHeight()
    {
    return height;
    }
    public void setHeight(float height)
    {
    this.height=height;
    }
    public double calculateVolume()
    {
    return calculateArae()*height;
    }
    public String toString()
    {
    String s="轴心坐标["+x+","+y+"],半径:"+radius+",高:"+height+",体积:"+new java.util.Formatter().format("%,.2f",calculateVolume());
    return s;
    }
    public static void main(String[] args)
    {
    Cylinder c1=new Cylinder(1,2,4.0f,6.0f);
    Cylinder c2=new Cylinder(3,6,8.0f,6.0f);
    Cylinder c3=new Cylinder(23,34,45.5f,7.7f);
    Cylinder c4=new Cylinder(65,44,5.6f,1.43f);
    Cylinder c5=new Cylinder(98,23,1.45f,85.67f);
    Cylinder c6=new Cylinder(3,76,3.4f,9.5f);
    Cylinder c7=new Cylinder(25,9,66.7f,4.0f);
    Cylinder c8=new Cylinder(99,33,4.5f,23.2f);
    Cylinder c9=new Cylinder(56,87,38.6f,98.2f);
    System.out.println(c1);
    System.out.println(c2);
    System.out.println(c3);
    System.out.println(c4);
    System.out.println(c5);
    System.out.println(c6);
    System.out.println(c7);
    System.out.println(c8);
    System.out.println(c9);
    }
    }
      

  10.   

    我是看到标题后进来pia楼主的~