3 Replies - 386 Views - Last Post: 17 October 2019 - 09:12 AM Rate Topic: -----

#1 KnowledgeMan Element   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 16-October 19

How to load text document in an array of objects?

Posted 16 October 2019 - 02:40 AM

hello everyone, I am very new to programing and need advise on this project.
I am trying to create a program that can can load data from a text document such as username or age into an array of object and not too sure how to do it. So far I created this code;
public class student {
public String username;
public String firstname;
public String lastname;
public int    age;

public student () {

    username = " ";
    firstname = " ";
    lastname = " ";
         age = 0;
}
  public void displayname() {
 System.out.println("username: " + username);
 System.out.println("firstname: " + firstname);
 System.out.println("lastname: " + lastname);
 System.out.println("age: " + age);
}
}

public class democlass {

public static void main(String[] args) {

student s1= new student();
student s2= new student();
student s3= new student();
student s4= new student();
student s5= new student();

student[] studentinfo = new student[5];

}
}
:code:

I have to take the following data from a text file:
MarieJ, Marie, Joelle, 21
PaulP, Paul, Pierre, 28
JuanJ, Juan, Jesus, 27
JackM, Jack, Meta,25
PhilT, Phil, Tompson, 29

Insert the data in the an array of student objects. Any advise on how to do it ??
thanks

This post has been edited by modi123_1: 17 October 2019 - 07:55 AM
Reason for edit:: In the future, please use the [code] tag button in the editor.


Is This A Good Question/Topic? 0
  • +

Replies To: How to load text document in an array of objects?

#2 NormR   User is offline

  • D.I.C Lover
  • member icon

Reputation: 797
  • View blog
  • Posts: 6,062
  • Joined: 25-December 13

Re: How to load text document in an array of objects?

Posted 16 October 2019 - 04:21 AM

Quote

Insert the data in the an array of student objects. Any advise on how to do it ??

What steps would the program need to take to do that? Can you list the steps?
Was This Post Helpful? 0
  • +
  • -

#3 KnowledgeMan Element   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 16-October 19

Re: How to load text document in an array of objects?

Posted 17 October 2019 - 07:54 AM

[quote name='NormR' date='16 October 2019 - 04:21 AM' timestamp='1571224888' post='2407004']

Quote

Insert the data in the an array of student objects. Any advise on how to do it ??

What steps would the program need to take to do that? Can you list the steps?
1)create a student class which is accessible to other classes with the instance variable as age, firstname etc.
2)build an array of the student objects and load the data from a university.txt for ex;(MarieJ, Marie, Joelle, 21).
I manage to do the first step but got stuck on the second one. Can you help me plzz??

This post has been edited by NormR: 17 October 2019 - 09:10 AM

Was This Post Helpful? 0
  • +
  • -

#4 NormR   User is offline

  • D.I.C Lover
  • member icon

Reputation: 797
  • View blog
  • Posts: 6,062
  • Joined: 25-December 13

Re: How to load text document in an array of objects?

Posted 17 October 2019 - 09:12 AM

Quote

got stuck on the second one

There are too many parts to the second one. Break it down further.

The first step was to define a Student class. Now the code needs to
1)create an instance of that class for each student,
2)fill it with data from the file
3)and save that instance in the array.

This post has been edited by NormR: 17 October 2019 - 09:13 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1