Results 1 to 2 of 2
  1. #1
    mrjaeyun is offline Member
    Join Date
    Nov 2011
    Posts
    4
    Rep Power
    0

    Default 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?

  2. #2
    mrjaeyun is offline Member
    Join Date
    Nov 2011
    Posts
    4
    Rep Power
    0

    Default 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

  1. Replies: 2
    Last Post: 09-06-2010, 02:03 AM
  2. store array of arrays in array of arrays
    By joost_m in forum New To Java
    Replies: 4
    Last Post: 04-19-2010, 11:32 AM
  3. How do i make a bunch of arrays into a list?
    By mxrider in forum New To Java
    Replies: 11
    Last Post: 03-24-2010, 01:02 AM
  4. want to make an array
    By doha786 in forum New To Java
    Replies: 3
    Last Post: 03-29-2009, 02:49 AM
  5. Replies: 9
    Last Post: 06-25-2008, 05:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •