String split to create variable names
I hope my question makes sense. I am parsing data for 10 cities through the BufferedReader class and using this information further downstream in my code. It all works fine, however, I am trying to compress the repetitive unweildy parts in the code to a single function where only the names are being changed. At present I have 10 identical functions (with only the names changing), one for each city, called inside void draw(), and looks like this:
void parseManchester()
{
try
{
String line = reader[0].readLine();
if (line == null)
{
}
else
{
String [] bits = line.split(",");
float valuesMANCHESTER = float(bits[0]);
float MANCHESTERnormalised;
MANCHESTERnormalised = norm(valuesMANCHESTER, minNorm, maxNorm);
MANCHESTERlist.add(MANCHESTERnormalised); }
int numCities = 10;
String cityNames = ("MANCHESTER,LONDON,WASHINGTON,DAKAR,CHICAGO,SHANGAI,TOKYO,ATLANTA,
LUTON,RIO,NAIROBI");
Works fine to here. This is where I am getting stuck, trying to use the parsed names to create variables inside the function:
void matrixParse()
{
for (int i = 0; i < numCities; ++i)
{
try
{
String line = reader[0].readLine();
if (line == null)
{
}
else
{
String [] bits = line.split(",");
//println ("values"+nameList[i]); // comes out fine: valuesMANCHESTER, valuesLONDON etc
String valCity = "values" + nameList[i]; // comes out fine: valuesMANCHESTER, valuesLONDON etc
float valCity = float(bits[0]); // PROBLEM HERE: can't use valCity again because the
float MANCHESTERnormalised;
MANCHESTERnormalised = norm(valuesMANCHESTER, minNorm, maxNorm);
MANCHESTERlist.add(MANCHESTERnormalised);
}
}
Might someone have an idea how to overcome this problem? Thanks in advance.