• Post Reply Bookmark Topic Watch Topic
  • New Topic

Hey I could use some guidance  RSS feed

 
akshar shah
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey I last posted here as a arrogant junior in high school who didn't know he had ADHD. Anyway, rn I'm in college and my major is Computer Science , funny how things work eh?

up vote
-9
down vote
favorite
Okay so I have a project due for my computer programming class. I've been working on this code for a while. Logically, I can't seem to figure out why it doesn't work because logically its correct.

Okay for my "Course" class, I wanna search by StudentNumber and return the whole line if it contains the studentNumber. But it won't work heres my AddStudent:



Question 2. I can't seem to search in this too by title and return whole line.


Question 3 :

Okay so this is what I need to do. For every keyboard input of addCourse , I want to create a separate ArrayList for every course given, so I can ensure the capacity of each course and I have a method that prints but I don't know how to make separate ArrayList's for every course given so I am just doing this and using a " for each if contains " loop. If I can have a separate ArrayList for every course given by the keyboard in Addcourse, then I can ensure the capacity of each one and print the available courses just for that arraylist.


Question 4: Sorry I'm a noob. How would I create a method that prints a given input from keyboard student's schedule? What fields would I need? I have title, time, and location as fields in the parameter (bluJ uses parameters to store to memory). But I need a separate ArrayList for every student so I can only print that student's schedule.

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

you should be creating a "Course" class to hold these four fields. Ditto for "Student".

Your post is a mess you need to make sure that the Code tags are properly placed before clicking Submit. I fixed it for you this time but please be more careful.
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know the specifics of your requirements but you might consider using a Map<String,Student> where String is the student's id and Student is the Student object. Then you can search by id using Map's get() method.
 
Knute Snortum
Sheriff
Posts: 4289
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Think about this code for a second: If the List studentNames contains the studentNumber anywhere, if will always return true.  So when you loop over studenNames, if the List contains the studentNumber, it will print out every student.  That's not what you want, surely.

I agree with Carey Brown that you need student to be an object of a class you write, and that you should have a Map of these objects.  Then finding the Student object by studentNumber becomes a trivia matter.

Look into this and rewrite your code, the post the update where.  And please UseCodeTags (that's a link).
 
Knute Snortum
Sheriff
Posts: 4289
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you post this question to StackOverflow?  If so, please post a link to that question here and inform StackOverflow that you posted here.  Cross-posting (as it's called) is okay at the CodeRanch only if you tell us that you're doing it.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!