求大神帮帮我,在线等,急
publicclassClassroom{publicTeacherteacher;//保存教师publicStudent[]students=newStudent[40...
public class Classroom {
public Teacher teacher; //保存教师
public Student[] students = new Student[40]; //保存学生
public int count = 0; //保存学生数量
public Teacher getTeacher() {
//返回教室中的教师
return teacher;
}
public Student[] getStudents() {
//返回所有的学生
return student;
}
public void setTeacher(Teacher tea) {
//更换教师
Teacher(int id, String name, double salary, int clRoomId, int age);
}
public void addStudent(Student stu) {
//增加学生
stu++;
}
public boolean removeStudent(int idx) {
//删除学生
}
public int getStudentNum() {
//返回教室中学生的数量
return student;
}
public void print() {
//输出当前教室中的教师和学生的信息
System.out.println(
}
}
public class ClassroomTest {
public static void main(String[] args) {
//创建Classroom对象
Classroom c=new Classroom();
//创建Teacher对象,并将Teacher分配到Classroom中
Teacher t=new Teacher();
t.Classroom();
//创建3个Student对象,并将Student分配到Classroom中
Student s1=new Student();
Student s2=new Student();
Student s3=new Student();
s1.Classroom();
s2.Classroom();
s3.Classroom();
//调用Classroom中的其它方法,测试方法的业务逻辑是否准确
c.setTeacher(Teacher tea);
c.addStudent(Student stu);
c.removeStudent(int idx);
c.getStudentNum();
c.print();
}
}
public class Teacher {
public int id;
public String name;
public double salary;
public int clRoomId;
public int age;
public Teacher(){ }
public Teacher(int id, String name, double salary, int clRoomId, int age) {
this.id = id;
this.name = name;
this.salary = salary;
this.clRoomId = clRoomId;
this.age = age;
}
public void print() {
System.out.println("---- Teacher ----");
System.out.println("id:" + this.id);
System.out.println("name:" + name);
System.out.println("salary:" + salary);
System.out.println("classroom id:" + clRoomId);
System.out.println("age:" + age);
}
}
public class Student {
public int id;
public String name;
public int age;
public void print() {
System.out.println("------ Student ------");
System.out.println("id:" + id);
System.out.println("name:" + name);
System.out.println("age:" + age);
}
public Student(int sId, String sName, int sAge) {
id = sId;
name = sName;
age = sAge;
}
} 展开
public Teacher teacher; //保存教师
public Student[] students = new Student[40]; //保存学生
public int count = 0; //保存学生数量
public Teacher getTeacher() {
//返回教室中的教师
return teacher;
}
public Student[] getStudents() {
//返回所有的学生
return student;
}
public void setTeacher(Teacher tea) {
//更换教师
Teacher(int id, String name, double salary, int clRoomId, int age);
}
public void addStudent(Student stu) {
//增加学生
stu++;
}
public boolean removeStudent(int idx) {
//删除学生
}
public int getStudentNum() {
//返回教室中学生的数量
return student;
}
public void print() {
//输出当前教室中的教师和学生的信息
System.out.println(
}
}
public class ClassroomTest {
public static void main(String[] args) {
//创建Classroom对象
Classroom c=new Classroom();
//创建Teacher对象,并将Teacher分配到Classroom中
Teacher t=new Teacher();
t.Classroom();
//创建3个Student对象,并将Student分配到Classroom中
Student s1=new Student();
Student s2=new Student();
Student s3=new Student();
s1.Classroom();
s2.Classroom();
s3.Classroom();
//调用Classroom中的其它方法,测试方法的业务逻辑是否准确
c.setTeacher(Teacher tea);
c.addStudent(Student stu);
c.removeStudent(int idx);
c.getStudentNum();
c.print();
}
}
public class Teacher {
public int id;
public String name;
public double salary;
public int clRoomId;
public int age;
public Teacher(){ }
public Teacher(int id, String name, double salary, int clRoomId, int age) {
this.id = id;
this.name = name;
this.salary = salary;
this.clRoomId = clRoomId;
this.age = age;
}
public void print() {
System.out.println("---- Teacher ----");
System.out.println("id:" + this.id);
System.out.println("name:" + name);
System.out.println("salary:" + salary);
System.out.println("classroom id:" + clRoomId);
System.out.println("age:" + age);
}
}
public class Student {
public int id;
public String name;
public int age;
public void print() {
System.out.println("------ Student ------");
System.out.println("id:" + id);
System.out.println("name:" + name);
System.out.println("age:" + age);
}
public Student(int sId, String sName, int sAge) {
id = sId;
name = sName;
age = sAge;
}
} 展开
2个回答
展开全部
this.teacher=tea;
追问
//创建Teacher对象,并将Teacher分配到Classroom中
Teacher t=new Teacher();
t.Classroom();
这个分配是什么意思啊?
追答
你确定这是对的么?你写的Teacher类里面都没有这个方法- -!,应该是
c.setTeacher(t);才是正确的操作
仔细看下你的Classroom和ClassroomTest基本都是错的,我帮你改了下,代码太多贴不出来,我发附件了
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |