Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Class Arrays passing / returning

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have two classes. The first collects input data and calls a second class for inputing data from a file. After the data is read I would like to use it inother classes but am having problems getting the data back.
To save space I will only show part of class I (calling class) which works, and all of class II that inputs the data O.K., but does not return it to class I:
CLASS I (Partical)
.
.
.
try
{
Climate.climaticData(County); // this works
}
catch (FileNotFoundException e)
{
}
catch (IOException e)
{
}


System.out.println(climateDataOut[3]); // Does not print element 3
.
.
.
CLASS II
Reads data O.K.
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.StringTokenizer;
/**
#######################################################
# @author RON_C
#######################################################
*/
public class Climate
{
/**
* Method LineOfStars.
* @param string
*/
public static void climaticData(String County)
throws FileNotFoundException, IOException
{
System.out.println(County + " Second File");
String[ ] climateDataOut = new String[45];
int i = 0;
String climate = null;
BufferedReader brclimate =
new BufferedReader(new FileReader("d:\\Java Info\\Jclimate.txt"));
while ((climate = brclimate.readLine()) != null)
{
if (County.substring(0, 4).equals(climate.substring(0, 4)))
{
StringTokenizer st = new StringTokenizer(climate, ",", false);
while (st.hasMoreTokens())
{
climateDataOut[i] = st.nextToken();
i++;
}
}
}

}
}

Thanks...Ronnie
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sending this one to the Java In General (Intermediate Forum) as it has nothing to do with GUI stuff.
 
Ranch Hand
Posts: 539
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just a thought...

Does it print element 4, or not work at all? Arrays are indexed from zero, so climateDataOut[3] is the fourth element...
Cheers,

--Tim
 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's a little bit of code that should show you the way.




It prints "delta".


Regards.
 
Paddy spent all of his days in the O'Furniture back yard with this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic