私は、教授をコースのインストラクターにすることになっています。この方法の上のコメントには、目的が記載されています。しかし、私はこれについてどうやって行くのか混乱しています。私はjavaでプログラミングするのが初めてで、教授が "instanceof"の比較をしてコースに入ったかどうかを確認することにしました。私は正しい方向に向かったのか、何かが恋しいのか?ありがとうございました!要素の追加と削除
最後に近づいて2つの方法が追加されました。私はgetStudentsを正しく実装していないと思います。最後の2つの方法は、学生の追加と削除を要求します。私はキーと値のペアが学生のためになるかどうかはわかりません。
パブリッククラスコースは、それらが登録されていない場合は同等{
/** * course id (unique) */ private int id; /** * course name */ private String name; /** * course level */ private int level; /** * professor teaching the course, null if none */ private String professor; /** * students enrolled in the course (unique), empty if none */ private HashSet<String> students; /** * Create a course. Initially there is no professor or student for the * course. * * @param id course id * @param name course name * @param level course level */ public Course(int id, String name, int level) { this.id = id; this.name = name; this.level = level; this.professor = null; this.students = new HashSet<>(); } /** * Get the course id. * * @return course id */ public int getId() { return id; } /** * Get the course name. * * @return course name */ public String getName() { return name; } /** * Get the course level. * * @return course level */ public int getLevel() { return level; } /** * Get the professor teaching the course. * * @return the professor, if none, null */ public String getProfessor() { return professor; } /** * Get the students enrolled in the course. * * @return the students, organized by ascending hash codes. if there are no * students enrolled the list should be empty. */ public Collection<String> getStudents() { return students; } /** * Make a professor the instructor of this course. If another professor was * teaching it, that information is lost. * * @param username the username of the professor */ public void addProfessor(String username) { }
} /**
- が一定時間に
- 、コースに学生を追加実装しています。 *
- @paramのユーザー名の学生の名
- */ 学生が追加されたかどうかを@returnか公共ブールaddStudent(文字列のユーザー名){// TODO はfalseを返す 。 }
/**
- それらが登録されている場合は、もちろんから
- を学生を外し、一定時間内に。 * 学生は、偽の削除された場合、学生はもちろん */ パブリックブールremoveStudent(文字列のユーザー名){ になかった場合は、学生のユーザ名が
- @return真を削除する
- @paramのユーザー名//TODO falseを返します。 }
任意のチェックを行うことなく、あなたは、単に教授として与えられた値を設定できることを意味し 'addProfessor'方法についてのコメントは、以前の教授が新しい教授によって上書きされるだろうと言うので、あなたが実際に持っています教授がすでにコースに入っていたかどうか確認してください。 – badjr
学生メソッドの追加と削除を実装するには、Setのaddメソッドとremoveメソッドを見てください。 http://docs.oracle.com/javase/8/docs/api/java/util/Set.html –