例如,我在绕过传递类作为变量时遇到了困难 - 例如 - 我正在考虑学校以及如何实现一个简单的系统来跟踪事物如作为变量传递一个类 - 学校示例 - Java
- 学生
- 教师
- 主题
使得下列条件:
- 一个学生需要主题
- 教师教一个主题
- 一个主题既有学生和教师
每个类的一个基本的例子是如如下:
Student.java
private String name;
private int age;
private Subject subject;
private String school; // Can implement another class of School later
public Student(int id, String name, int age, String school, String course) {
this.id = id;
this.name = name;
this.age = age;
this.school = school;
this.course = subject;
}
Teacher.java
private String name;
private Subject subjectTaught;
private Date taughtSince; // Date is another thing that perplexes me, but that can be saved for another time
private int holidaysRemaining;
public Teacher(int id, String name, Subject subjectTaught, String taughtSince, int holidaysRemaining) {
this.id = id;
this.name = name;
this.subjectTaught = subjectTaught;
this.taughtSince = taughtSince;
this.holidaysRemaining = holidaysRemaining;
}
主题
String name;
int length;
Teacher teacher;
Student student;
public Subject(int id, String name, int length, Teacher teacher, Student student) {
this.id = id;
this.name = name;
this.length = length;
this.teacher = teacher;
this.student = student;
}
我明白,我可以实现一个ArrayList或主题内的HashMap来跟踪哪些学生服用哪些科目等。
我只是有点失落,当涉及到实际得到的代码下来,使事情发生......
的最终结果将是有某种用于CRUD操作的库存管理系统“,增加学生和教师对象等
任何指导将是伟大的!
所以你想要另一个对象存储一个学生和老师的主题? – Dinh
我对你的问题标题有点困惑。在班级或班级中,'class'是'class',如Java ['class'](https://docs.oracle.com/javase/8/docs/api/java/lang/Class)。 HTML)。 –
我修改了我的问题,让'科目'而不是'班'@Dinh – physicsboy