例如,我在繞過傳遞類作爲變量時遇到了困難 - 例如 - 我正在考慮學校以及如何實現一個簡單的系統來跟蹤事物如作爲變量傳遞一個類 - 學校示例 - 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