首页 > 代码库 > 面向对象综合1

面向对象综合1

package oop1;
/*1.编写出一个通用的人员类(Person),该类具有姓名(Name)、年龄(Age)、性别(Sex)等域。
然后对Person 类的继承得到一个学生类(Student),
该类能够存放学生的5门课的成绩,并能求出平均成绩。
最后在Main函数中对student类的功能进行验证。*/
public class Person {
String name;
int age;
String sex;
public Person(String name, int age, String sex) {
    super();
    this.name = name;
    this.age = age;
    this.sex = sex;
}


}
package oop1;

public class Student extends Person{
int yuwen;
int shuxue;
int yingyu;
int wuli;
int huaxue;





public Student(String name, int age, String sex, int yuwen, int shuxue,
        int yingyu, int wuli, int huaxue) {
    super(name, age, sex);
    this.yuwen = yuwen;
    this.shuxue = shuxue;
    this.yingyu = yingyu;
    this.wuli = wuli;
    this.huaxue = huaxue;
}


    public void showInfo(){
        System.out.println(this.name);
        System.out.println(this.age);
        System.out.println(this.sex);
    }
public double areafen(){
    double area= ((this.yuwen+this.shuxue+this.yingyu+this.wuli+this.huaxue)/5);
    System.out.println(area);
    return area;

}
        
}
package oop1;

public class Test {
public static void main(String[] args) {
    
    Student s=new Student("李华", 18, "", 90,100, 90, 80, 90);

    s.showInfo();
    s.areafen();
    
}
}

 

面向对象综合1