Array with a class overwrites old one
in
Programming Questions
•
2 years ago
- String [] alldays = new String[3];
- String [] fulldays = new String[6];
- int [][] days = new int [6][7];
- PersonDay[] person = new PersonDay[4];
- void setup(){
- size(200,200);
- //set everything to zero
- for (int a = 0; a < 6; ++a){
- for (int b = 0; b < 6; ++b){
- days[b][a] = 0;
- }
- }
- for (int a = 0; a < alldays.length; ++a) {
- person[a] = new PersonDay(days);
- }
- /// rip up the data ///
- alldays = loadStrings("time.txt");
- for( int a = 0; a < alldays.length; ++a){
- fulldays = split(alldays[a], ',');
- for( int l = 0; l < 6; ++l){
- days[l] = int(split(fulldays[l], '\t'));
- }
- /// put the data to apporpiate place in the array ///
- person[a].days = days;
- }
- /// see that it failed, placed person[1].days in person[0].days as well
- println(person[0].days[1][0]);
- }
- void draw(){
- }
the "time.txt" is this
and the class,1900 2200,,1530 2130,,0830 1130,,,1400 1700,1100 1400,1100 1300 1600 1800 1900 2100,1100 1600,1600 1700,,
- class PersonDay {
- int[][]days;
- PersonDay(int[][] days) {
- this.days = days;
- }
- }
So I don't understand why person[0].days is being the same as person[1].days?
Is there a better way to store 3 layers of data(thats all I really want to do)?
so that there is the person lvl, days lvl, time lvl. If it was working I would have this...
1