Win a copy of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 this week in the Programmer Certification forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

exercise for my school with methods

 
Saloon Keeper
Posts: 6424
61
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Johny Sougiospitos wrote:i believe that you never intended to help me...
Anyway it's my loss sinve i can't solve this exercise//and i am mad because teacher told us that this exercise will not take us more than 1 hour...and i am trying to solve it 5 days!  


Sorry you feel that way.

I feel that your instructor did you a disservice by claiming that you could do it in an hour. I spent more than an hour just thinking about your problem and maybe 2 hours testing pieces of the design I came up with to see if they'd work. Unfortunately you say you can't use Maps or Sets. That's a shame. Not that you couldn't have done without them but it would have increased the effort involved.

Part of my time was un-thinking some of what you presented, such as the bi-directional relationship between Student and Course. You showed them as List fields of those two classes which would have made it very difficult to manage and keep in sync. Later you hinted at needing a separate class to manage that but we never got to the point of pulling those fields out of Student and Course.

I wish you a better experience with your next project.
 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i showed them as lists because teacher told us to do so...i am still trying to solve it without success anyway..
The classes are the ones i created..Student/Course/Trainers

until now i can add and print the entries in each of these classes

To print Students per Course teacher told us to create a middle Class called "StudentPerCourse" and this is where i am getting confused..Let's say that the COURSE class has 2 courses like Algebra and Geometry.
in COURSE class i declare as
Course c1 = new Course("Algebra");
Course c2 = new Course("Geometry;

i can not figure out a way of how to present the students of each course...and that is what i can't do 5 days now

can i write something like that:

"Which course you want: Algebra or Geometry?"
"for Algebra press 1 and for Geometry press 2"
if option =1 then add student to course c1'
that's what i can't do

if i could do that then i thonk it would be easy to print students per course.

can you help me with the code here please???
That's the point i can't think anything and i am crying 4 days now

---i hope there will be not another project like that--i am gonna die ----
 
Carey Brown
Saloon Keeper
Posts: 6424
61
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not entirely sure how StudentsPerCourse is supposed to work but here's a stab.
Then in School you might have
Then to pick a Student to display all the courses they are enrolled in
Loop through all the students and display the List to the user as a numbered list and let the user choose the student number.

Then, using the student number get the Student reference. Using the Student reference loop through your studentsPerCourse and find all entries where 'student' matches your Student reference and then print the course associated with that.

This should work but this alone is at least an hour to implement and debug.
 
Johny Sougiospitos
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Carey Brown wrote:I'm not entirely sure how StudentsPerCourse is supposed to work but here's a stab.
Then in School you might have
Then to pick a Student to display all the courses they are enrolled in
Loop through all the students and display the List to the user as a numbered list and let the user choose the student number.

Then, using the student number get the Student reference. Using the Student reference loop through your studentsPerCourse and find all entries where 'student' matches your Student reference and then print the course associated with that.

This should work but this alone is at least an hour to implement and debug.




that's where i am confused and i do not know what to do
in Class StudentPerCourse i have that

and that i do not know how it is supposed to help me!
and what kind of method to create with what kind of loop
 
Carey Brown
Saloon Keeper
Posts: 6424
61
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Johny Sougiospitos
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Carey Brown wrote:



silly question...in a similar way i print the list of all students..

why should the user select one student??



and one thin i just thought...if in Class Courses i create a method addStudent (return Student) doesn't that work with Course1,course2 etc? i can use Course1.addStudent right?
 
Carey Brown
Saloon Keeper
Posts: 6424
61
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Johny Sougiospitos wrote:that's where i am confused and i do not know what to do
in Class StudentPerCourse i have that

and that i do not know how it is supposed to help me!
and what kind of method to create with what kind of loop

This is exactly where I got stuck on your project. This requires a bit of un-thinking. What you need is a bi-directional relationship. That is: you have Students dependent on Courses while at the same time you have Courses dependent on Students. There can be a collection (e.g. list) of these relationships but the Student+Course combination must be unique in the collection. This is why I find even the name StudentPerCourse inappropriate because it implies some sort of directional dependency when it's actually a bi-directional dependency. You'll need to be able to go through this collection looking for all entries for a particular Student and do something useful with the corresponding Course (e.g. print it). Conversely, you'll also need to be able to go through the collection looking for all entries for a particular Course and do something useful with the corresponding Student.
 
Carey Brown
Saloon Keeper
Posts: 6424
61
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Johny Sougiospitos wrote:

Carey Brown wrote:



silly question...in a similar way i print the list of all students..

why should the user select one student??



and one thin i just thought...if in Class Courses i create a method addStudent (return Student) doesn't that work with Course1,course2 etc? i can use Course1.addStudent right?


The scenario that I can think of is if you want to enroll one student in one class.

Same applies for selecting a Course. Display a numbered list of Courses and let the user choose one. If you wanted to get fancy I suppose you could let the user select multiples and return a list but I'd stick with the basics first.
 
Johny Sougiospitos
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Carey Brown wrote:
The scenario that I can think of is if you want to enroll one student in one class.

Same applies for selecting a Course. Display a numbered list of Courses and let the user choose one. If you wanted to get fancy I suppose you could let the user select multiples and return a list but I'd stick with the basics first.



that's what i am trying to do..to have a list of courses like Maths- computer science etc and make the user choose which one/ones he wants..and with his option to have something like
if choice =maths
then math.addstudents ++;
else choice = computer science
computer.addstudents++
else if (choice == maths ) and (choice== computer science)
computer.addstudents++
math.student++
and when i print them should be something like
math:
john
Carey etc

but i can't write the specific code..i am confused
 
Carey Brown
Saloon Keeper
Posts: 6424
61
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Johny Sougiospitos wrote:i can use Course1.addStudent right?


This is where I'd use ManageStudentCourseRelationship.
 
Johny Sougiospitos
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Carey Brown wrote:

Johny Sougiospitos wrote:i can use Course1.addStudent right?


This is where I'd use ManageStudentCourseRelationship.



the  "..." what's supposed to mean??
the "manageStudentcourseRelationship" is the name of the method???Large name!!

can you please write it more detailed??


you mean in the school Class -which is tthe main-- write that method?

i can see what you want to tell me but it seems i am not as good as you in the code writing..
and i think i should be write simpler code since i am beginner.
 
Carey Brown
Saloon Keeper
Posts: 6424
61
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Carey Brown
Saloon Keeper
Posts: 6424
61
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Johny Sougiospitos wrote:the  "..." what's supposed to mean??

Ellipses means there's stuff that's been left out because it is either not important to the discussion or is left as an exercise to the developer.
 
Carey Brown
Saloon Keeper
Posts: 6424
61
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Johny Sougiospitos wrote:the "manageStudentcourseRelationship" is the name of the method???Large name!!

Yes, I'd pick a shorter name but I wanted to get the point across.

you mean in the school Class -which is the main-- write that method?

Yes.

i can see what you want to tell me but it seems i am not as good as you in the code writing..
and i think i should be write simpler code since i am beginner.

This is just not an easy problem, no matter what your instructor says.
 
Johny Sougiospitos
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
okay...my code is that


this is the point i must create a method in Class Course -perhaps- to do the things i told you.. how should i use what you purpose??

---My head is gonna explode soon--


 
Carey Brown
Saloon Keeper
Posts: 6424
61
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Johny Sougiospitos wrote:the "ManageStudentCourseRelationship" is the name of the method???Large name!!

Actually, the name of a class.
 
Johny Sougiospitos
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Carey Brown wrote:This is just not an easy problem, no matter what your instructor says.



you believe that what i am thinking to do difficult/easy/stupid?

 
Johny Sougiospitos
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Carey Brown wrote:

Johny Sougiospitos wrote:the "ManageStudentCourseRelationship" is the name of the method???Large name!!

Actually, the name of a class.


i got it..it's something like the middle class my teacher said "StudentPerCourse"
 
Carey Brown
Saloon Keeper
Posts: 6424
61
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Johny Sougiospitos wrote:okay...my code is thatthis is the point i must create a method in Class Course -perhaps- to do the things i told you.. how should i use what you purpose??


This is too hard coded. Presumably your School class has a List<Course> courseList. You can write a generic method that allows a user to select one of the available Courses.
This will work when you add and delete courses.
 
Carey Brown
Saloon Keeper
Posts: 6424
61
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Johny Sougiospitos wrote:

Carey Brown wrote:

Johny Sougiospitos wrote:the "ManageStudentCourseRelationship" is the name of the method???Large name!!

Actually, the name of a class.


i got it..it's something like the middle class my teacher said "StudentPerCourse"

Precisely, except in a more bi-directional dependent sort of way.
 
Carey Brown
Saloon Keeper
Posts: 6424
61
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Johny Sougiospitos wrote:

Carey Brown wrote:This is just not an easy problem, no matter what your instructor says.



you believe that what i am thinking to do difficult/easy/stupid?


I just think that this is a heck of a problem to throw at a beginner. I think you are doing well wrestling with this task and I wouldn't be too hard on yourself.
 
Johny Sougiospitos
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Carey Brown wrote:
This is too hard coded. Presumably your School class has a List<Course> courseList. You can write a generic method that allows a user to select one of the available Courses.
This will work when you add and delete courses.



also, i don not quite understand your code..can you explain it to me??and why is it necessary the "to String" method?

Teacher told us to have a list with courses and the user can only add othe courses not delete..
So if the user doesn't want to add a new course ,he/she must choose from the existing ones..
that's the reason i was thinking the "code" i wrote before
 
Carey Brown
Saloon Keeper
Posts: 6424
61
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Johny Sougiospitos wrote:Teacher told us to have a list with courses and the user can only add othe courses not delete..
So if the user doesn't want to add a new course ,he/she must choose from the existing ones..
that's the reason i was thinking the "code" i wrote before

Well, if you want to pre-fill courseList with hard-coded courses, that's fine, it's just that the code you write shouldn't be dependent on that.
 
Johny Sougiospitos
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Carey Brown wrote:

Johny Sougiospitos wrote:Teacher told us to have a list with courses and the user can only add othe courses not delete..
So if the user doesn't want to add a new course ,he/she must choose from the existing ones..
that's the reason i was thinking the "code" i wrote before

Well, if you want to pre-fill courseList with hard-coded courses, that's fine, it's just that the code you write shouldn't be dependent on that.




it becomes hardier and hardier!!!
 
Marshal
Posts: 66266
250
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Johny Sougiospitos wrote:   thanks for all the help . . .

That's a pleasure I am sorry that your exercise didn't work out.

Although I only played a small part in this discussion, we really were trying to help. Giving you too much information or a complete solution wouldn'tt have helped you, so I think your allegation in your last post is unfair to those who have put a lot of effort into this discussion.
 
Johny Sougiospitos
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:

Johny Sougiospitos wrote:   thanks for all the help . . .

That's a pleasure I am sorry that your exercise didn't work out.

Although I only played a small part in this discussion, we really were trying to help. Giving you too much information or a complete solution wouldn'tt have helped you, so I think your allegation in your last post is unfair to those who have put a lot of effort into this discussion.



sometimes though giving a solution helps if the other can't solve it...and then i would remember what i have to do if a similar problem occurs..

Anyway i am still trying to figure out what to do here
 
Marshal
Posts: 7272
492
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suggest you post full instructions you were given, and the code templates you were given without any of your additions. There is a chance you misunderstood, misinterpreted stuff.

Give guys to have a look so could give an opinion whether it is too hard.

Which course you are at once again? Which year?
 
Johny Sougiospitos
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Liutauras Vilda wrote:I suggest you post full instructions you were given, and the code templates you were given without any of your additions. There is a chance you misunderstood, misinterpreted stuff.

Give guys to have a look so could give an opinion whether it is too hard.

Which course you are at once again? Which year?



ok...Teacher gave us this and asks:

the user should be able to put data in the classes or if he doesn't want to put data to use existing ones..

1.create the classes with setters/getters
2. print the lists of students/courses/trainers/assignments
3.print the students per course
4.print the trainers per course


so as you see he doesn't give us many details...so,i do not tknow what i exactly i have to do and try to imagine what this program should probably do

that's the exersice..As for me ..i am studying Java for 1 month and teacher told us to use List/Arraylist to solve it
 
Liutauras Vilda
Marshal
Posts: 7272
492
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, did you implement how to add Student to Course? It is pretty hard to follow this thread (just re-read it twice). You mentioned that you can use Lists only.

So, did you implement the part I mentioned above?

I'd expect to be able to use code like that:
And get printed:
Liutauras Vilda

Pretty much similar implementation with Trainer. Got that one? Works in a similar way?

If you have that (that really can be done in 5-10 minutes), then you are quite close to achieving all those 4 requirements you were given.
 
Marshal
Posts: 14399
240
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sometimes I feel like the teacher needs to bear most of the blame for the student's failure to understand. Such is the case here. It seems to me like you've been overwhelmed by too much information and too little context given so that you can apply all that information properly towards solving the problem given. I also think the solution being asked or hinted at is too specific and slanted towards a certain way of implementing the program that gives no room for exploration or alternative and equally valid or maybe even better implementations.
 
Johny Sougiospitos
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think i found a way to put student to courses.. I do not know if it is the best one out there... But at least it shows that i tried.
 
I'm not dead! I feel happy! I'd like to go for a walk! I'll even read a tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!