Bennett
asked on
java arrays
Hello have what is probably a small problem, I have a java array class with this code in it:-
int NUMBER_OF_YEARS = 5;
String yearsWorked[] = {"First Year", "Five Years", "10 Years", "Fifteen Years", "Twenty Years"};
double[] total_Wages = new double[NUMBER_OF_YEARS];
/**
* arrays class fills the array with the users input
*/
public void Arrays() throws IOException
{
double sum = 0;
for (int i = 1; (i <=NUMBER_OF_YEARS); i++)
{
System.out.println("Enter amount you expect to earn after "+yearsWorked[i-1]);
//create an instance of the readline class
UserInput wages_Earned = new UserInput();
double wage = wages_Earned.readDouble();
sum+= wage;
total_Wages[i-1] = wage;
what I want to do is refrence a specific location from another class I have tried using:-
arrayInput = arrayInput.total_Wages[4];
but this does not work any ideas much apreciated thanks.
int NUMBER_OF_YEARS = 5;
String yearsWorked[] = {"First Year", "Five Years", "10 Years", "Fifteen Years", "Twenty Years"};
double[] total_Wages = new double[NUMBER_OF_YEARS];
/**
* arrays class fills the array with the users input
*/
public void Arrays() throws IOException
{
double sum = 0;
for (int i = 1; (i <=NUMBER_OF_YEARS); i++)
{
System.out.println("Enter amount you expect to earn after "+yearsWorked[i-1]);
//create an instance of the readline class
UserInput wages_Earned = new UserInput();
double wage = wages_Earned.readDouble();
sum+= wage;
total_Wages[i-1] = wage;
what I want to do is refrence a specific location from another class I have tried using:-
arrayInput = arrayInput.total_Wages[4];
but this does not work any ideas much apreciated thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
yes arrayInput is an instance of the class containing the method.
the error I get is
found double required Arrays
the error I get is
found double required Arrays
> arrayInput = arrayInput.total_Wages[4];
this line doesn't make any sense.
if arrayInput is the instance of your class, your are trying to assign total_Wages[4] (a double) to your instance which is of type Arrays.
this line doesn't make any sense.
if arrayInput is the instance of your class, your are trying to assign total_Wages[4] (a double) to your instance which is of type Arrays.
ASKER
sorry yeah youre right the line is
wages = arrayinput.totalWages[4]
wages = arrayinput.totalWages[4]
so is it working now?
if not, what is wages? it should be a double.
if so, please accept a comment as answer so this can be moved to PAQ (previously asked questions)
if not, what is wages? it should be a double.
if so, please accept a comment as answer so this can be moved to PAQ (previously asked questions)
ASKER
sorry yeah youre right the line is
wages = arrayinput.totalWages[4]
wages = arrayinput.totalWages[4]
ASKER
Ok its not a race, thanks for the help, you can have the points now. ;-)
ASKER
Thanks very much for the help.
I take it arrayInput is an instance of the Class which contains the above method?