0

Read in students file. For each student ID create a Student object. Set that objects name to the name in the file after the student ID. Add the Student object to the map with the student ID as the key. Read in courses file. For each student ID, lookup the Student object from the map. Read the credit hour line in the file. Read the grade line in the file. Create a Course object using the credit hour and grade. Add that Course object to the Student object's collection of courses.

Here is my code which reads in the information from the file:

    FileReader freader = new FileReader(nameFile);
    BufferedReader Breader = new BufferedReader(freader);
    boolean end = Breader.ready();

        do {
            next = Breader.readLine();
            sNumber = Integer.parseInt(next);
            formatSNumber = String.format("%03d", sNumber);
            //Assignment the formatted number to my HashMap
            sName = Breader.readLine();
            //Assignment the name to my HashMap
            end = Breader.ready();
        } while(end);

I am completely lost on how to do this.

I know how to create a student object:

Student student1 = new Student();

However, I need each name, "student1", to be different depending upon the information read in.

For example, if I read "001" and "Julie Jones", I want my student object to be

Student student1 = new Student();

And then the next one to be

Student student2 = new Student();

For Student studenti = new Student();, where i = the number of student IDs read in from the file.

8
  • What is Breader? This class is not part of the standard JDK. Commented Dec 13, 2016 at 0:51
  • It's an instance of BufferedReader. Sorry, I added some code for clarity. Commented Dec 13, 2016 at 0:54
  • 1
    create a Student object If this is beyond your ability then I suggest getting some one-on-one tuition Commented Dec 13, 2016 at 0:56
  • 1
    There must be hundreds of examples on how to read in a text file that can be found just on SO Commented Dec 13, 2016 at 0:58
  • 1
    You do not need to have different variables names for your Student BECAUSE every time that your loop iterates it re-declares the Student object and the code re-initialises the values that will be stored in the Student Object. These objects can within the loop be added to an ArrayList Commented Dec 13, 2016 at 1:41

1 Answer 1

1

Yo, I think the question is a bit misleading. "objects name" means students name-- not the name of the objects reference variable. What I'm reading is that you will need to create a student object with their Name passed in as a parameter.

I think it should be something like this (psudocode):

//create a map//
for each line in file {
    int id=//GET THE ID//
    String name=//GET THE STUDENTS NAME//
    Student student=new Student(name);
    map.add(student, id);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.