There are three kinds of actuaries: those who can count, and those who can't.
Piet Souris wrote:Isn't that a task that the School should perform? It seems that the School should maintain Lists of Students, Courses, Teachers and the like. Does your menu in the School class have a option to add/delete a Student?
There are three kinds of actuaries: those who can count, and those who can't.
Piet Souris wrote:I had a look at your Student class. What I missed (I may have overlooked it) is a constructor Student(String firstName, String secondName, String birthdate) {...}
Now, in your Schoolclass, have a field List<Student> students. In the 'add student' method, you ask the user for the FirstName, the SeconName and the Birthday, and then you do: sudents.add(new Student(firatnme, secondname, birthday) and you are done.
Add an option to your schoolmenu: 'print list of Students' that simply does:
Carey Brown wrote:Alternatively
So, NO SETTERS for those.Johny Sougiospitos wrote:as for what you ask..Student name and Birthdate won't change
Only create SETTERS if APPROPRIATE.so,the first thing is to create classes and setters/getters right;
Carey Brown wrote:
So, NO SETTERS for those.Johny Sougiospitos wrote:as for what you ask..Student name and Birthdate won't change
Only create SETTERS if APPROPRIATE.so,the first thing is to create classes and setters/getters right;
Carey Brown wrote:Your requirements are a bit vague here but I would probably consider creating and adding a new Student to be a totally separate operation from adding a Course to a Student, seeing as how you could always come back at a later time to add another Course to the same Student.
On a different topic, this is just me nit-picking, I don't like your choice of the variable name 'listOfStudentsDetails'. It's a mouthful without adding any useful information to the description. You have a class succinctly named 'Student' not 'StudentDetails', so why say 'StudentDetails' here? 'listOf' is subject to various opinions. Just saying 'students' (plural) should get the point across without tying you to a List implementation, on the other hand, knowing that you are dealing with a List is often useful. My personal vote would have been for 'studentList' because the important part is 'student' and 'list' is just for clarification.
Adrian Grabowski wrote:In your Course class you have methods setStudent() and getStudent() which are confusing as they are setting and returning the whole list.
Instead you probably want methods like addStudent(Student student) and removeStudent(Student student), inside them you would change content of the list and at the same time you could also add course to the Student object.
Campbell Ritchie wrote:I didn't notice at first, but there is more to say than what AG said.
Why would you want a setXXX() method in the first place? Do you really think it is necessary to change the entire List of students attending a particular course? And returning the List unchanged allows others to modify the course without your knowing about it. You can write...but that looks a bit awkward. If you look here, you will find four other ways to return a List; some of them dissociate changes in one List from the other.
Johny Sougiospitos wrote:Teacher told us to make setters/getters for everything we have in the class...if they are necessary or not i don't know..i haven't understood how am i supposed to do some of the things this exercise asks..
Johny Sougiospitos wrote:Question..In student i have private lists course and assignment...it's because i have them there that i can unite them?
if i create the addStudent method in Class COURSE means i can use it in Student class?
Carey Brown wrote:Student has-a list of Courses and Course has-a list of Students. This may be a way to implement it but it means that neither Course nor Student can manage this bi-directional relationship.
There are three kinds of actuaries: those who can count, and those who can't.
Liutauras Vilda wrote:
Carey Brown wrote:Student has-a list of Courses and Course has-a list of Students. This may be a way to implement it but it means that neither Course nor Student can manage this bi-directional relationship.
That's a very good point. It can work one way actually, the one I showed in tests, but not the both ways. But I agree, that can be error-prone.
Liutauras Vilda wrote:
To be honest I'm quite surprised you were given such an interesting/good assignment at the level of age you are, most of the students learning that stuff only in universities. I'm at that age was still playing with a ball in the backyard... So good learnings for you
Carey Brown wrote:A "Map" has a "key" and a "value". The key must be unique and it is used to insert and retrieve an associated value. A key may be of any type and a value may be of any type. Here we are using a key that is an instance of a Student. And because a Student can belong to zero or more Courses, the value is a List of Courses. If we want to add a Student to a Course we first use the Student as the key and retrieve the List<Course> (i.e. "the value"). If the new Course is in the list then we don't need to do anything, otherwise we need to add the new Course to the List and then re-add the list back to the map using the same key. If the key is not found then the value returned is null.
Now, we can save a step by using a Set<Course> instead of a List<Course>. A "Set" only permits a single copy of an object to exist inside the set, so the business of looking to see if it already exists is taken care of for us. So, now we have...
This maps one Student to N Courses.
We also need to look up Students by Courses, so we need a map that maps one Course to N Students. This looks like...
Then we throw in a manager method that updates both of these maps with a given Student and Course (and Course and Student) to the two maps in order to maintain them in sync.
Liutauras Vilda wrote:Now, try to identify those within your requirements, and see what you get. Share with us, so we understand better too.
Johny Sougiospitos wrote:the system allows user to put entries to Students/courses/trainers/assignments once or more than one time
Liutauras Vilda wrote:
Johny Sougiospitos wrote:the system allows user to put entries to Students/courses/trainers/assignments once or more than one time
What entries? Please come up with something clear and unambiuous. Don't think about all of them in one go.