简单类(多对多练习)


class Student{
    private int id;
    private String name;
    private Studentcourse[] studentcourse;
    public Student(){

    }
    public Student(int id,String name){
        this.id=id;
        this.name=name;
    }
    public String getInfo(){
        return id+" "+name;
    }
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }

    public Studentcourse[] getStudentcourse() {
        return studentcourse;
    }
    public void setStudentcourse(Studentcourse[] studentcourse) {
        this.studentcourse = studentcourse;
    }


}
class Course{
    private int cid;
    private String name;
    private Studentcourse[] studentcourse;
    public Course(){
        }
    public Course(int cid,String name){
        this.cid=cid;
        this.name=name;
    }
    public String getInfo(){
        return this.cid+" "+this.name;
    }
    public int getCid() {
        return cid;
    }
    public void setCid(int cid) {
        this.cid = cid;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public Studentcourse[] getStudentcourse() {
        return studentcourse;
    }
    public void setStudentcourse(Studentcourse[] studentcourse) {
        this.studentcourse = studentcourse;
    }



}
class Studentcourse{
    private Student student;
    private Course course;
    private double score;
    public Studentcourse(){

    }
    public Studentcourse(Student student,Course course,double score){
        this.student=student;
        this.course=course;
        this.score=score;
    }
    public Student getStudent() {
        return student;
    }
    public void setStudent(Student student) {
        this.student = student;
    }
    public Course getCourse() {
        return course;
    }
    public void setCourse(Course course) {
        this.course = course;
    }
    public double getScore() {
        return score;
    }
    public void setScore(double score) {
        this.score = score;
    }
}


public class pratice {
    public static void main(String args[]){
        Student stu1=new Student(1,"zhangsan");
        Student stu2=new Student(2,"lisi");
        Student stu3=new Student(3,"wangwu");
        Course ca=new Course(1001,"math");
        Course cb=new Course(1002,"eng");
        stu1.setStudentcourse(new Studentcourse[]{
            new Studentcourse(stu1,ca,90.0),
            new Studentcourse(stu1,cb,80.0)
        });
        stu2.setStudentcourse(new Studentcourse[]{
                new Studentcourse(stu2,ca,70.0) 
            });
        stu3.setStudentcourse(new Studentcourse[]{
                new Studentcourse(stu3,cb,60.0) 
            });
        ca.setStudentcourse(new Studentcourse[]{
                new Studentcourse(stu1,ca,90.0),
                new Studentcourse(stu2,ca,70.0) 
        });
        cb.setStudentcourse(new Studentcourse[]{
                new Studentcourse(stu1,cb,80.0),
                new Studentcourse(stu3,cb,60.0) 
        });

        System.out.println(ca.getInfo());
        for(int x=0;x<ca.getStudentcourse().length;x++){
            System.out.println(ca.getStudentcourse()[x].getStudent().getInfo()+" "+ca.getStudentcourse()[x].getScore());

        }
        System.out.println(cb.getInfo());
        for(int y=0;y<cb.getStudentcourse().length;y++){
            System.out.println(cb.getStudentcourse()[y].getStudent().getInfo()+" "+cb.getStudentcourse()[y].getScore());

        }
        System.out.println("********************************");
        System.out.println(stu1.getInfo());
        for(int x=0;x<stu1.getStudentcourse().length;x++){
            System.out.println(stu1.getStudentcourse()[x].getCourse().getInfo()+" "+stu1.getStudentcourse()[x].getScore());
        }



    }

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值