Win a copy of Python Continuous Integration and Delivery this week in the Python 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
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

Logic for adding students  RSS feed

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I'm new here,so pardon me if i'm doing something wrong.I'm having a problem in Java which I really hope that you guys can help me to figure out.I have to create a program that will add students to courses ,and add courses to students.
I have an arraylist to contain my created courses(course name,course code). I also have another arraylist to store my students(name,id).Now, I can't figure out how to add a student to a course or vice versa! I've been trying to do this for 3 days now....Please advise.
public void addStudentToCourse( Student student )
{
   for(Course c:Clist)
   {
      //Clist.add(student);
   }
   
 
   
   
}

I know this is wrong,but I think it's something close to this.
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your current code when the commented line is not commented will try to add your student into the list of courses. Now a list of Courses and Students mixed together would indeed not be what you want and if Clist is of type Course would even give you an error.

There are multiple ways of solving this, you can either give the Student an empty list of Courses where you add the courses to the list in the Student object. Or you can add an empty list of students to your Course and add the student to a students list in the Course object.
You can also let both objects have a list where you add persons to courses and courses to persons. But: then you have double data which would be redundant and can result in inconsistent data. Since person has its own list, and course has its own list.

You may want to think first about what approach you would like to make, and write it down to get an idea.
 
Master Rancher
Posts: 1161
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It sounds like homework... So I won't post a full solition.
I don't know if you just created the array's or also maded classes for the courses and the students.
If you did the lather, you should have a instance variable which is a list of students(let's call it enrolledStudents) and make a enrollStudent method that takes a student as a parameter in the course class.
After you created the students to enroll and the course to enroll to you can enroll a student by calling the enrollStudent method of the to enroll to course and pass the to enroll student as parameter.
In the enrollStudent method you add the parameter to enrolledStudents. Make sure your enrolledStudents has a getterMethod too...
 
Joel Drake
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Koen Ursem wrote:Your current code when the commented line is not commented will try to add your student into the list of courses. Now a list of Courses and Students mixed together would indeed not be what you want and if Clist is of type Course would even give you an error.

There are multiple ways of solving this, you can either give the Student an empty list of Courses where you add the courses to the list in the Student object. Or you can add an empty list of students to your Course and add the student to a students list in the Course object.
You can also let both objects have a list where you add persons to courses and courses to persons. But: then you have double data which would be redundant and can result in inconsistent data. Since person has its own list, and course has its own list.

You may want to think first about what approach you would like to make, and write it down to get an idea.



What I did is that I created a course by entering the course attributes which are (course name,course code). Now second step is to add a student to the created course. Now I can't figure out how to do so.Can you provide me with a sample code to do that?
I have a class called CourseList which I provide methods in there,so I made a method called addStudentToCourse(){}  .I don't know what to write inside this method.Please shed some light here
 
Joel Drake
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:It sounds like homework... So I won't post a full solition.
I don't know if you just created the array's or also maded classes for the courses and the students.
If you did the lather, you should have a instance variable which is a list of students(let's call it enrolledStudents) and make a enrollStudent method that takes a student as a parameter in the course class.
After you created the students to enroll and the course to enroll to you can enroll a student by calling the enrollStudent method of the to enroll to course and pass the to enroll student as parameter.
In the enrollStudent method you add the parameter to enrolledStudents. Make sure your enrolledStudents has a getterMethod too...


It's indeed an assignment, I'm not asking for a solution,I like programming actually,but I don't know how to add students to the courses after storing my course in an arraylist
 
Daniel Demesmaecker
Master Rancher
Posts: 1161
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I you have a seperate class for your courses who have enrolled students in them it's not enough to pass only the student. You have to create an array who keeps track of the course and the enrolled students (I would use a hashmap).
so you have to pass both student and course, then in the function looping the hasmap searching for the course and adding the student, but the way I descriped before is way easier.
 
Joel Drake
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:I you have a seperate class for your courses who have enrolled students in them it's not enough to pass only the student. You have to create an array who keeps track of the course and the enrolled students (I would use a hashmap).
so you have to pass both student and course, then in the function looping the hasmap searching for the course and adding the student, but the way I descriped before is way easier.


Unfortunately,I'm not allowed to use hashmaps,arraylist  is fine though.
 
Daniel Demesmaecker
Master Rancher
Posts: 1161
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


This could be an example for your courseclass.


*Note for moderator: "Why (even when I remove the codetags) do I get a  bold tag everytime I press space to try to indent my code? I don't have that prob when I copy paste code from ide...
 
Koen Ursem
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:I you have a seperate class for your courses who have enrolled students in them it's not enough to pass only the student. You have to create an array who keeps track of the course and the enrolled students (I would use a hashmap).
so you have to pass both student and course, then in the function looping the hasmap searching for the course and adding the student, but the way I descriped before is way easier.



A Hashmap would be a neat solution, but considering this is an assignment I think OP is more looking for a simple list<Student> implementation in the Course object.


@OP
If you want to add a student to your course, you would need a list/array in your course object to save this in.
Then when you want to add the student you want to call this course object and run a method that adds the student you have given to this list/array.

Considering the code from your first code, something like this  'c.addStudent(yourStudent);' in the for loop. Be aware that your for loop is running over all courses in your Clist, so now the student would be enrolled to all courses if you implement the suggested method. I will let you try to figure that part out for yourself for now, let us know if you can figure it out or not
 
Joel Drake
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Koen Ursem wrote:

Daniel Demesmaecker wrote:I you have a seperate class for your courses who have enrolled students in them it's not enough to pass only the student. You have to create an array who keeps track of the course and the enrolled students (I would use a hashmap).
so you have to pass both student and course, then in the function looping the hasmap searching for the course and adding the student, but the way I descriped before is way easier.



A Hashmap would be a neat solution, but considering this is an assignment I think OP is more looking for a simple list<Student> implementation in the Course object.


@OP
If you want to add a student to your course, you would need a list/array in your course object to save this in.
Then when you want to add the student you want to call this course object and run a method that adds the student you have given to this list/array.

Considering the code from your first code, something like this  'c.addStudent(yourStudent);' in the for loop. Be aware that your for loop is running over all courses in your Clist, so now the student would be enrolled to all courses if you implement the suggested method. I will let you try to figure that part out for yourself for now, let us know if you can figure it out or not



Regarding the problem of adding a student to all courses,I think I will have to first search for the student to be added by ID,then search for the wanted course by course code,than call the enroll method.Anyway, I first have to find out how to add I believe I'm very close now.
Sry I don't know how to insert a code like you do guys,so I will insert photos and please tell  me what it is that I'm doing wrong.Note that I created this small program just to ease things for me to understand.

MainClass:https://gyazo.com/107eef612122ad6a3fe2760eae4b3c48

Student class: https://gyazo.com/0ee624a57774b79763fcc5e4ca8d0311
The rest of student class is just setters and getters and a display method.

Course:https://gyazo.com/c8810e82418550b4e1ce244f8481cbdb
https://gyazo.com/7169a7b677b7d4698833305a296e6c7c
 
Koen Ursem
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Only thing I see wrong right now is that you print this.student in the displaycourseinfo instead of this.enrolledstudents (You may have to find a way to print a list correctly).
your course class is now holding both a student object and a enrolledstudents list right now, but it could be this was your intention to have that student be the teacher of the course or something?

And yes, when you have more students and courses to work with you may want to have a way of selecting the right ones. Something in the trend of if student.name = ?? then do this. Same for course.
 
Joel Drake
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Koen Ursem wrote:Only thing I see wrong right now is that you print this.student in the displaycourseinfo instead of this.enrolledstudents (You may have to find a way to print a list correctly).
your course class is now holding both a student object and a enrolledstudents list right now, but it could be this was your intention to have that student be the teacher of the course or something?

And yes, when you have more students and courses to work with you may want to have a way of selecting the right ones. Something in the trend of if student.name = ?? then do this. Same for course.


No I eventually have to look for a specific course by course code then display all enrolled students in that course. I tried this.enrolledstudents

and this what I got
https://gyazo.com/243cbc5af333f48383e1873f6a305549
 
Sheriff
Posts: 13155
219
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's see, you have a list of courses. You have a student that you want to enroll in a course.  You already have a way to enroll a student in a course through the Course.enrollStudent() method.

So, isn't your only problem now really to figure out a way to find the course in the list of courses?

So Google for "how to iterate over a list in Java"

Then, as you iterate through each course in the list of courses, how do you know you've found the right course that the student wants to enroll in?

When you find the right course, then wouldn't you just go ahead and call the appropriate method on that course?
 
Marshal
Posts: 63383
205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I don't know what the bug is causing HTML tags to appear, but they don't appear if you write &nbsp; instead of leading spaces. We are working on it.

Joel Drake wrote: . . . and this what I got
https://gyazo.com/243cbc5af333f48383e1873f6a305549

Unfortunately many people are reluctant to look at other sites like that. I did, and couldn't read it all which shows why we discourage screenshots.

I think you are going to have to start from the beginning. You have got some code working and some not; that is normal. I think many people design from centre→periphery and code from periphery→centre, so you would expect to have some code working. But I think you need to go back to your design. What does the structure of your program look like? Do you have some sort of class in the middle, possibly called College? Presumably you have multiple Course objects and multiple Student objects. And the College object will store them all somehow. Let's imagine you have a method whereby you can add a course, like this:- add(new Course("EN123", "Basic English Literature"); Get that working, with the most basic Course class you can write, and it will look like this:-That is about as rudimentary as you can get and still pass into your add() method. Once you get add() working, and you find nothing else will work because I have removed 90% of your Course class, start putting the Course class back together, bit by bit, and make sure it continues to work. Compile and run your code after every new method you write.
 
Joel Drake
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Junilu Lacar wrote:Let's see, you have a list of courses. You have a student that you want to enroll in a course.  You already have a way to enroll a student in a course through the Course.enrollStudent() method.

So, isn't your only problem now really to figure out a way to find the course in the list of courses?

So Google for "how to iterate over a list in Java"

Then, as you iterate through each course in the list of courses, how do you know you've found the right course that the student wants to enroll in?

When you find the right course, then wouldn't you just go ahead and call the appropriate method on that course?


Well  what I have in mind is something like

Enter the course to enrol to
for( Course c:Clist)
if(value==c.getcoursecode())
Enter the ID of the student to be enrolled
for(Student s:Slist)
if(id==s.getId())
enrolledstudents.add(student)
 
Joel Drake
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Welcome to the Ranch

I don't know what the bug is causing HTML tags to appear, but they don't appear if you write &nbsp; instead of leading spaces. We are working on it.

Joel Drake wrote: . . . and this what I got
https://gyazo.com/243cbc5af333f48383e1873f6a305549

Unfortunately many people are reluctant to look at other sites like that. I did, and couldn't read it all which shows why we discourage screenshots.

I think you are going to have to start from the beginning. You have got some code working and some not; that is normal. I think many people design from centre→periphery and code from periphery→centre, so you would expect to have some code working. But I think you need to go back to your design. What does the structure of your program look like? Do you have some sort of class in the middle, possibly called College? Presumably you have multiple Course objects and multiple Student objects. And the College object will store them all somehow. Let's imagine you have a method whereby you can add a course, like this:- add(new Course("EN123", "Basic English Literature"); Get that working, with the most basic Course class you can write, and it will look like this:-That is about as rudimentary as you can get and still pass into your add() method. Once you get add() working, and you find nothing else will work because I have removed 90% of your Course class, start putting the Course class back together, bit by bit, and make sure it continues to work. Compile and run your code after every new method you write.




I already have a method to creat a course,but the problem is to add students to it.
 
Bartender
Posts: 5632
56
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm one of those people that avoid clicking links that I'm not familiar with. Please post your entire piece of code when you get a chance.
 
Daniel Demesmaecker
Master Rancher
Posts: 1161
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this could be your main method:



One thing I forgot to do in in my previous example of the course class is to initialize the enrolledLIst, you could use the constructor for that or just hardcode it
 
Daniel Demesmaecker
Master Rancher
Posts: 1161
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Joel Drake wrote:
No I eventually have to look for a specific course by course code then display all enrolled students in that course. I tried this.enrolledstudents

and this what I got
https://gyazo.com/243cbc5af333f48383e1873f6a305549


I think you now should have enough pieces to complete the puzzle.
use the scanner to ask for the courseId, loop through the courses to find the correct one and us the getEnrolledStudents to get the list of enrolled students, then loop through that list and print their names.
 
Marshal
Posts: 6588
443
BSD Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:this could be your main method:


Well.

Class names usually are spelt as singular. Not Students, but Student. Not Courses, but Course.

This main method is too long. Ideally, main method supposed to start an application and nothing else, i.e.:

You can find more information in one of our tutorials: MainIsAPain
 
Daniel Demesmaecker
Master Rancher
Posts: 1161
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Liutauras Vilda wrote:
Class names usually are spelt as singular. Not Students, but Student. Not Courses, but Course.

This main method is too long. Ideally, main method supposed to start an application and nothing else, i.e.:



I give you the classnames, but for the main method you have to take in account the level of experience of the op.
Normally the main would start an userinterface of some kind, which would launch the needed methods, since this isn't an option here...

If you wanted you could split up the code in seperated method and call thoose from the main, but would that make such a big difference?
 
Liutauras Vilda
Marshal
Posts: 6588
443
BSD Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:Normally the main would start an userinterface of some kind, which would launch the needed methods, since this isn't an option here...


Daniel Demesmaecker wrote:


That seems like user interface.

OP can read the tutorial I gave earlier, there is all well explained. The level of experience shouldn't be a problem. It is good that OP can get this information earlier rather than later and start implementing in own projects.
 
Joel Drake
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:

Liutauras Vilda wrote:
Class names usually are spelt as singular. Not Students, but Student. Not Courses, but Course.

This main method is too long. Ideally, main method supposed to start an application and nothing else, i.e.:



I give you the classnames, but for the main method you have to take in account the level of experience of the op.
Normally the main would start an userinterface of some kind, which would launch the needed methods, since this isn't an option here...

If you wanted you could split up the code in seperated method and call thoose from the main, but would that make such a big difference?


https://gyazo.com/7da0329c642d6758626b94d4cbc17b5c
As you can see in the pic. It needs to be text based or a menu if you will.Would you recommend me to have my inputs  in the other class which contains then method?Regardless of all that, I still haven't figured out how to add students to courses
I thought I got the hang of it,but I'm still having an issue.Look at the output above. I used this.enrolledstudents, but it didn't work.
 
Liutauras Vilda
Marshal
Posts: 6588
443
BSD Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That reads like an interesting, fairly small, meant to be object oriented project.

Would recommend to start from the first bullet point, one step at a time.
 
Joel Drake
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Liutauras Vilda wrote:That reads like an interesting, fairly small, meant to be object oriented project.

Would recommend to start from the first bullet point, one step at a time.



This is actually what I'm trying to do, I'm trying to to use multiple classes+inheritance+polymorphism, and all other possible stuff I'm having 8 classes including the main class.I don't know now if I should put my input in other classes or keep them in the main one
 
Daniel Demesmaecker
Master Rancher
Posts: 1161
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Joel Drake wrote:

Daniel Demesmaecker wrote:
As you can see in the pic. It needs to be text based or a menu if you will.Would you recommend me to have my inputs  in the other class which contains then method?Regardless of all that, I still haven't figured out how to add students to courses
I thought I got the hang of it,but I'm still having an issue.Look at the output above. I used this.enrolledstudents, but it didn't work.



The answer to how to add a student to a course is already bin given several times...
Look at the code examples that have bin posted.
you have a Student.class, a Course.class and a Main.class.
In your Course.class you have an arrayList of type Student, a getter for that array and a enrollStudent method.
In the enrollStudent method you add the student (list.add(Student);)

 
Daniel Demesmaecker
Master Rancher
Posts: 1161
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Joel Drake wrote:
This is actually what I'm trying to do, I'm trying to to use multiple classes+inheritance+polymorphism, and all other possible stuff I'm having 8 classes including the main class.I don't know now if I should put my input in other classes or keep them in the main one



8 classes? Inheritance? You making it way more complicated then it has to be...
Maybe you should post your code...
 
Joel Drake
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:

Joel Drake wrote:

Daniel Demesmaecker wrote:
As you can see in the pic. It needs to be text based or a menu if you will.Would you recommend me to have my inputs  in the other class which contains then method?Regardless of all that, I still haven't figured out how to add students to courses
I thought I got the hang of it,but I'm still having an issue.Look at the output above. I used this.enrolledstudents, but it didn't work.



The answer to how to add a student to a course is already bin given several times...
Look at the code examples that have bin posted.
you have a Student.class, a Course.class and a Main.class.
In your Course.class you have an arrayList of type Student, a getter for that array and a enrollStudent method.
In the enrollStudent method you add the student (list.add(Student);)



Sry I didn't see the long main class you posted.I think I did the same thing!
Have a look at this plssss.
Main class


Course class

 
Joel Drake
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh man why does it look like this?

 
Daniel Demesmaecker
Master Rancher
Posts: 1161
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can loose the Student instance variable in your Course.class and I would replace the displayMethod with a toString().
But for the rest I don't see what the problem is...
 
Daniel Demesmaecker
Master Rancher
Posts: 1161
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Joel Drake wrote:Oh man why does it look like this?



That's what I ment with the note to the moderator in my first post. Remove the spaces or use the htmltag for space;
 
Campbell Ritchie
Marshal
Posts: 63383
205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Joel Drake wrote:Oh man why does it look like this?

It doesn't any more because I got rid of all your spaces.

That also gave me a chance to see what you are writing, but I am afraid it isn't good. You should have a College object (or similar) which holds lists of students and courses; that is what happens in real life too. You have got those Lists floating in some sort of limbo in the main() method, which is not what the main() method is intended for. Also, give those lists proper names; you followed slist with a comment that it is the student List, when you could have called it studentList (or similar) and made its meaning obvious. (By the way: note where the Capital Letter belongs.)
You didn't show us the student class, but I think you need to think again about the Course class. The version I reformatted had a constructor taking a student (yes, just one) and one taking a name etc. That isn't how things work in real life. You have a course with a name, and you publicise it, and then students turn up to enrol. It is possible to have a course without any students but every Course a name and ID. Once you have got that sorted out, you can consider how you are going to regiester all the students on a particular course. Don't try to do it all at once; divide your task into small bits and it will work a lot better.
 
Joel Drake
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:

Joel Drake wrote:Oh man why does it look like this?

It doesn't any more because I got rid of all your spaces.

That also gave me a chance to see what you are writing, but I am afraid it isn't good. You should have a College object (or similar) which holds lists of students and courses; that is what happens in real life too. You have got those Lists floating in some sort of limbo in the main() method, which is not what the main() method is intended for. Also, give those lists proper names; you followed slist with a comment that it is the student List, when you could have called it studentList (or similar) and made its meaning obvious. (By the way: note where the Capital Letter belongs.)
You didn't show us the student class, but I think you need to think again about the Course class. The version I reformatted had a constructor taking a student (yes, just one) and one taking a name etc. That isn't how things work in real life. You have a course with a name, and you publicise it, and then students turn up to enrol. It is possible to have a course without any students but every Course a name and ID. Once you have got that sorted out, you can consider how you are going to regiester all the students on a particular course. Don't try to do it all at once; divide your task into small bits and it will work a lot better.


Well,you're right about sorting and how messy it looks,but as I have stated this program I made today just to try to understand how to enroll students.I do have another program that is divided into 8 classes.I also have a method to create courses so students can enroll to.I called my main class as CourseRegistrationSystem.
 
Campbell Ritchie
Marshal
Posts: 63383
205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please don't quote the whole of a previous post; that simply makes the thread longer without adding new information.
Don't go thinking that you don't need to take care of small programs. If this is intended to form part of a larger program, you will simply transfer any errors you make here into the larger program. So it needs to be written just as carefully.
 
Joel Drake
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apologies for the inconvenience. All I want from that small program is the logic. I won't be taking any code from there I want to see how things should work,then apply the logic to my big program.
 
Campbell Ritchie
Marshal
Posts: 63383
205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You still need the small program written correctly.
 
Joel Drake
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you guys for helping me.Still didn't quite get it,bu I'll keep on trying.
 
Campbell Ritchie
Marshal
Posts: 63383
205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Start from scratch. Create a Student class with name only and no other fields. Give it a toString() method and no other methods. Create a Course method with ID only. Put the courses into a data structure. Put the students on a course into a data structure. Once you have done that, you will have your little app working, and you can use what you learnt in the bagbig app.
 
Roses are red, violets are blue. Some poems rhyme and some don't. And some poems are a tiny ad.
Become a Java guru with IntelliJ IDEA
https://www.jetbrains.com/idea/
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!