Re: Trouble with arrays Help
First of all, there are actually alot of errors in your code. You should probably go over the basics.
That aside, in your constructor :
Code:
/////////constructors///////////////
public Budget() {}
public Budget(String name) {this.expenseName = name;}
public Budget(String name, int num)
{
this.expenseName = name;
this.expenseAmount = num;
this.monthNumber = num;
}
this.expenseAmounts and this.monthNumber is expecting an array object. Thats why its keeps giving you the error, cannot convert int to int[]. If you want to pass in or take out a value
from the array you should define where in the array you want to put it in ie expenseAmounts[i] where [i] is the arrangement of the value in the array starting from 0.
Re: Trouble with arrays Help
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};
/////////constructors///////////////
public Budget() {}
public Budget(String name) {this.expenseName = name;}
public Budget(String name, int num)
{
this.expenseName = name;
this.expenseAmount[1] = num;
this.monthNumber[3] = num;
}
/////////////methods///////////
public String getexpenseName() {return expenseName;}
public int getexpenseAmount() {return expenseAmount[1];}
public int getmonthNumber() {return monthNumber[1];}
public void setExpenseName(String name)
{
this.expenseName = name;
}
public boolean setexpenseAmount(int num)
{
if (this.expenseAmount[0] == 0)
{this.expenseAmount[1] = num;
return true;
}
else
return false;
}}
I put the [] brackets where it was needed and put temporary numbers within them for compiling sakes. Could you direct on how to go about doing the assignment?
Re: Trouble with arrays Help
Sounds like you are just guessing.
If you want an explanation of the assignment then you should talk to your teacher. If you have a specific question about your code then ask it and we can provide a specific answer. "I don't know what to do" is not specific and very difficult for us to answer.