I'm creating an assignment in Java and I've instantiated an array with length of 69 (I didn't mean for it to be that number, it just happened to be it)
anyway, I HARD-CODED the values of all the values in the array. The array is made up of a class I made up called Currency, which has 4 values. Two strings, symbol and name, and two doubles, fromDollar and toDollar
I have 69 x 4 lines of code dedicated to hardcoding the values into the array. I did it like this:
Currency[] change = new Currency[69];
change[0].symbol = "DZD";
change[1].symbol = "USD";
change[2].symbol = "AUD"; and so on and so forth
but at the end, if I put in a for loop that reads:
for (int i = 0; i < change.length; i++) {
System.out.println(change.symbol);
}
I get the very last value 69 times. change[0].symbol is "ZWD" and change[68].symbol is also "ZWD"
anyway, I HARD-CODED the values of all the values in the array. The array is made up of a class I made up called Currency, which has 4 values. Two strings, symbol and name, and two doubles, fromDollar and toDollar
I have 69 x 4 lines of code dedicated to hardcoding the values into the array. I did it like this:
Currency[] change = new Currency[69];
change[0].symbol = "DZD";
change[1].symbol = "USD";
change[2].symbol = "AUD"; and so on and so forth
but at the end, if I put in a for loop that reads:
for (int i = 0; i < change.length; i++) {
System.out.println(change.symbol);
}
I get the very last value 69 times. change[0].symbol is "ZWD" and change[68].symbol is also "ZWD"