编写Java程序完成:数据表与简单Java类的对应。按以下要求完成。
-
辅导员表(counselor),包含字段:辅导员编号(cid,int型),姓名(cname,String型)
-
班级表(theclass),包含字段:班级编号(tid,int型),班级名称(tname,String型)
-
学生表(student),包含字段:学生编号(sid,int型),学生姓名(sname,String型)
根据这三张表,写出对应的简单Java类,找出类之间的关系,设置联系数据,输出联系数据。
-
通过一个辅导员输出他管理的所有班级信息和所有对应的学生信息
-
通过某个班级对象输出管理该班级的辅导员信息和该班级中所有学生的信息
-
通过某个学生对象输出他对应的辅导员信息和他所在班级信息
class counselor { private int cid; private String cname; private Student student; private TheClass theclass; public counselor(int cid, String cname) { this.cid = cid; this.cname = cname; } public void setStudent(Student student) { this.student = student; } public Student getStudent() { return this.student; } public void settheclass(TheClass theclass) { this.theclass = theclass; } public TheClass gettheclass() { return theclass; } public String getInfo (){ return "辅导员编号:" + this.cid + ",辅导员姓名:" + this.cname; } }class TheClass { private Student student; private counselor counselor; private int tid; private String tname; public TheClass(int tid,String tname) { this.tid = tid; this.tname = tname; } public void setcounselor(counselor counselor) { this.counselor = counselor; } public counselor getcounselor() { return this.counselor; } public void setStudent(Student student) { this.student = student; } public Student getStudent() { return this.student; } public String getInfo() { return "班级编号:" + this.tid + ",班级姓名:" + this.tname; } }class Student { private TheClass theclass; private counselor counselor; private int sid; private String sname; public Student( int sid,String sname) { this.sid = sid; this.sname = sname; } public void setcounselor(counselor counselor) { this.counselor = counselor; } public counselor getcounselor() { return this.counselor; } public void setTheClass(TheClass theclass) { this.theclass = theclass; } public TheClass getTheClass() { return this.theclass; } public String getInfo() { return "学生编号:" + this.sid + ",学生姓名:" + this.sname; } }class TestDemo { public static void main(String[] args) { counselor c = new counselor(1,"萧闯"); counselor cc = new counselor(1,"萧闯"); counselor cs = new counselor(2,"李华"); Student s = new Student(1,"张三"); Student d = new Student(2,"李四"); Student e = new Student(3,"王五"); TheClass t = new TheClass(1,"大数据技术与应用"); TheClass th = new TheClass(2,"软件技术与工程"); TheClass tl = new TheClass(3,"计算机科学与技术"); c.setStudent(s); cc.setStudent(d); cs.setStudent(e); c.settheclass(th); cc.settheclass(t); cs.settheclass(tl); t.setcounselor(cc); th.setcounselor(c); tl.setcounselor(cs); t.setStudent(s); th.setStudent(d); tl.setStudent(e); s.setcounselor(c); d.setcounselor(cc); e.setcounselor(cs); s.setTheClass(t); d.setTheClass(th); e.setTheClass(tl); System.out.println(c.getStudent().getInfo()); System.out.println(c.gettheclass().getInfo()); System.out.println(cc.getStudent().getInfo()); System.out.println(cc.gettheclass().getInfo()); System.out.println(cs.getStudent().getInfo()); System.out.println(cs.gettheclass().getInfo()); System.out.println(""); System.out.println(s.getcounselor().getInfo()); System.out.println(s.getTheClass().getInfo()); System.out.println(d.getcounselor().getInfo()); System.out.println(d.getTheClass().getInfo()); System.out.println(e.getcounselor().getInfo()); System.out.println(e.getTheClass().getInfo()); System.out.println(""); System.out.println(t.getStudent().getInfo()); System.out.println(t.getcounselor().getInfo()); System.out.println(th.getStudent().getInfo()); System.out.println(th.getcounselor().getInfo()); System.out.println(tl.getStudent().getInfo()); System.out.println(tl.getcounselor().getInfo()); System.out.println(""); } }



