0

I have an assignment upcoming and I will quote the assignment(I am not asking you to do it for me, I just am confused at how to start)

Your task is to write a (very simple:-) student record system. You should be able to store details about students - their name, subject and a student number; as well as the level they have most recently completed ranging from 0 (meaning they are still in the first year) through to 3 (meaning they have graduated). It should also store their result for each level they have completed as a number 0-100. Your program should allow the user to enter student data for as many students as they want.

Would this be done via objects or not, as I am very confused on this part..

Any advice would be helpful, I can do everything bar this part.

Ceri Westcott
  • 59
  • 1
  • 8
  • *(I am not asking you to do it for me)* - this line prevented me (*moral decision*) from down-voting.. You should go through the basics of java and OOPs or talk to your teacher.. – TheLostMind Dec 01 '14 at 14:07
  • Thanks I guess, I know the basics of java and a little more but i might just be having a mind fluff right now @TheLostMind – Ceri Westcott Dec 01 '14 at 14:10
  • Related: http://stackoverflow.com/questions/6470651/creating-a-memory-leak-with-java – Stijn Geukens Dec 01 '14 at 14:10
  • @CeriWestcott - You can define a *Student* class with necessary fields like year, score name etc. Then in another method you ask for the number of students. Then create an `ArrayList` or `array` and keep adding students to it.. – TheLostMind Dec 01 '14 at 14:13
  • I get that but where would the object come into play, the way I was thinking of it was having setter methods and doing Student (x) = new Student(Name, subject, level, studentNo); but then wouldn't that create an object for that particular student, not as many as I want?@TheLostMind – Ceri Westcott Dec 01 '14 at 14:23

2 Answers2

1

The Student should be a class and contain all the properties mentioned. Once you have a Student class you can make Student objects allowing you to have an ArrayList<Student> which will therefore let you store as many students as you want. For example:

ArrayList<Student> students = new ArrayList<Student>();

while(youWantToReadStudents){
   Student student = new Student();
   // read and add student details
   students.add(student); // add student to ArrayList
}

Note how the loop allows you to add students to the ArrayList as long as youWantToReadStudents == true.

Cristian Gutu
  • 1,221
  • 1
  • 11
  • 24
  • This making a lot more sense but how do the arraylist and student objects work together? dont objects need some kind of unique identifier? such no two objects can be called the same thing? – Ceri Westcott Dec 01 '14 at 14:44
  • Like I said up there, I'm sure im having a mind fluff at the moment – Ceri Westcott Dec 01 '14 at 14:46
  • No two objects can be called the same thing in the same scope, so we are not breaking that rule here. The ArrayList simply stores each of the `student` object you create in every iteration. The "arraylist and objects work together" in a sense that you can access any of the objects you need and its properties. – Cristian Gutu Dec 01 '14 at 14:49
  • AH! Sorry I read the arrayList as a list of strings not of Students, this makes a lot more sense to me! Thank you! – Ceri Westcott Dec 01 '14 at 14:53
0

Start by thinking of what classes you need. I can see that you may need to create a Student class that has a name, subject and a student number, level, and list of levels completed with the number 0-100...

javaHunter
  • 1,097
  • 6
  • 9