Link to home
Start Free TrialLog in
Avatar of Bennett
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.
Avatar of TimYates
TimYates
Flag of United Kingdom of Great Britain and Northern Ireland image

what's the error?

I take it arrayInput is an instance of the Class which contains the above method?
ASKER CERTIFIED SOLUTION
Avatar of bobbit31
bobbit31
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bennett
Bennett

ASKER

yes arrayInput is an instance of the class containing the method.
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.
Avatar of Bennett

ASKER

sorry yeah youre right the line is
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)
Avatar of Bennett

ASKER

sorry yeah youre right the line is
wages = arrayinput.totalWages[4]
Avatar of Bennett

ASKER

Ok its not a race, thanks for the help, you can have the points now. ;-)
Avatar of Bennett

ASKER

Thanks very much for the help.