java arrays

Posted on 2003-02-24
Medium Priority
Last Modified: 2010-03-31
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.
Question by:Bennett
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
LVL 35

Expert Comment

ID: 8009924
what's the error?

I take it arrayInput is an instance of the Class which contains the above method?
LVL 18

Accepted Solution

bobbit31 earned 800 total points
ID: 8009926
you could make total_Wages data member public:

ie: public double[] total_Wages = ...

but the best practice is to create a getter:

public double[] getTotalWages() { return total_Wages; }

then you can do (assuming arrayInput is your class):

double[] totWages = arrayInput.getTotalWages();
myVal = totWages[4];

Author Comment

ID: 8010017
yes arrayInput is an instance of the class containing the method.
the error I get is
found double required Arrays
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

LVL 18

Expert Comment

ID: 8010051
> 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.

Author Comment

ID: 8010361
sorry yeah youre right the line is
wages = arrayinput.totalWages[4]
LVL 18

Expert Comment

ID: 8010425
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)

Author Comment

ID: 8010565
sorry yeah youre right the line is
wages = arrayinput.totalWages[4]

Author Comment

ID: 8010575
Ok its not a race, thanks for the help, you can have the points now. ;-)

Author Comment

ID: 8010579
Thanks very much for the help.

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
In this post we will learn different types of Android Layout and some basics of an Android App.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month14 days, 9 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question