Results 1 to 2 of 2
- 11-14-2011, 12:29 AM #1
Member
- Join Date
- Nov 2011
- Posts
- 4
- Rep Power
- 0
How do you make an array of arrays?
public class Budget{
///////////////fields////////////////
private String expenseName;
int expenseAmount[] = {1000, 2000, 3000, 4000, 5000, 6000};
int monthNumber[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
int i=0; // this is arbitrary. Never hard code numbers unless that number is never going to change. in that case you make a variable and define it.
int month_num;
int clothes[]=null;
int tuiton[]=null;
int transportation[]=null;
int food[]=null;
int housing[]=null;
/////////constructors///////////////
public Budget() {}
public Budget(String name) {this.expenseName = name;}
public Budget(String name, int num)
{
this.expenseName = name;
this.expenseAmount[i] = num;
this.monthNumber[i] = month_num;
}
/////////////methods///////////
public String getexpenseName() {return expenseName;}
public int getexpenseAmount() {return expenseAmount[i];}//change the I
public int getmonthNumber() {return monthNumber[i];}//change the i
public void setExpenseName(String name)
{
this.expenseName = name;
}
public boolean setexpenseAmount(int num)
{
if (this.expenseAmount[i] == 0)
{this.expenseAmount[i] = num;
return true;
}
else
return false;
}}
i think i created an array of expenses which is int expenseName. i need to an array for each for expense which is int clothes[], int tuition[]. how would i create do that?
- 11-14-2011, 12:34 AM #2
Member
- Join Date
- Nov 2011
- Posts
- 4
- Rep Power
- 0
Re: How do you make an array of arrays?
i changed the coding for expenseName a little bit
public class Budget{
///////////////fields////////////////
private String expenseName[];
int expenseAmount[] = {1000, 2000, 3000, 4000, 5000, 6000};
int monthNumber[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
int i=0; // this is arbitrary. Never hard code numbers unless that number is never going to change. in that case you make a variable and define it.
int month_num;
int clothes[]=null;
int tuiton[]=null;
int transportation[]=null;
int food[]=null;
int housing[]=null;
/////////constructors///////////////
public Budget() {}
public Budget(String name) {this.expenseName[i] = name;}
public Budget(String name, int num)
{
this.expenseName[i] = name;
this.expenseAmount[i] = num;
this.monthNumber[i] = month_num;
}
/////////////methods///////////
public String getexpenseName() {return expenseName[i];}
public int getexpenseAmount() {return expenseAmount[i];}//change the I
public int getmonthNumber() {return monthNumber[i];}//change the i
public void setExpenseName(String name)
{
this.expenseName[i] = name;
}
public boolean setexpenseAmount(int num)
{
if (this.expenseAmount[i] == 0)
{this.expenseAmount[i] = num;
return true;
}
else
return false;
}}
Similar Threads
-
Trying to make an array list // inserting an element to middle of array
By javanew in forum New To JavaReplies: 2Last Post: 09-06-2010, 01:03 AM -
store array of arrays in array of arrays
By joost_m in forum New To JavaReplies: 4Last Post: 04-19-2010, 10:32 AM -
How do i make a bunch of arrays into a list?
By mxrider in forum New To JavaReplies: 11Last Post: 03-24-2010, 12:02 AM -
want to make an array
By doha786 in forum New To JavaReplies: 3Last Post: 03-29-2009, 01:49 AM -
Make Java codes more simplier (Multidimensional Arrays)
By javanewbie in forum JCreatorReplies: 9Last Post: 06-25-2008, 04:48 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks