Create an array of objects

September 5, 2009 at 15:14:04
Specs: Windows Vista
I am lost on how to create each state object. Any help would be appreciated.

Build Array of State Objects. Using States.txt, you are to build an array of objects. You are to design and develop a class named State (in addition to your class named Main) and create 50 objects of type (class) State – one object for each record (line) from the input file. (You may use Scanner, although I prefer you did not). Each State object will have six properties defined individually as integers or Strings as appropriate for each State attribute. Here is an example of a line from the .txt file:

Massachusetts Boston MA 6147132 New_England 1


See More: Create an array of objects

Report •


#1
September 5, 2009 at 15:25:28
Sounds like a homework assignment.

Many here will help, but not do your work for you. Start with pseudo-code.


=====================================
Helping others achieve escape felicity

M2


Report •

#2
September 8, 2009 at 23:14:15
Each State object will have six properties defined individually as integers or Strings as appropriate for each State attribute.
What are these 6 State attributes ? Explain more clearly.

---------------------------------------------
By what I understand, if these 6 state attributes are the six separate words in the line Massachusetts Boston MA 6147132 New_England 1 then you can simply read the line and assign the six words to proper instance variables which you will declare in your States class. Create an object of States from main class and call its constructor passing it the string or proper attributes which it will then assign to it's instance variables and you have a State object.
As far as input is considered Scanner might help but you can do it with readLine() and then StringTokenizer to separate the words followed by wrappers to get your desired type (ie int ,string etc) of attributes.


Report •

Related Solutions


Ask Question