Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Several questions about this program

 
Stephen Herkins
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to create a program that outputs employee data. I read data from files, and I have to use these classes. I have not finished the output section yet, so I left it out for now.

I was wondering why I only get an [incompatible type] error for my accessor method in the grossPay class, when the accessor methods in the other two classes have nothing in them. Shouldn't they get some error?
Can anyone explain to me how to return these arrays correctly?

I was also wondering if I should put the write method in my main class, and if I initialized the arrays outside of the constructors correctly.
If there is anything incorrect with this code, please tell me what I should consider changing.
Thanks for any help you can give me.

 
Steve Fahlbusch
Bartender
Posts: 605
7
Mac OS X Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A couple of points......

If you are receiving an error -- post it, not your interpration of it, but the exact error (copy and paste it in the posting).

Now I took a few seconds to look at your code..you may not want double fields for holding money (currency) values.
 
Greg Brannon
Bartender
Posts: 563
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is grossPays; what is its type? Are you returning that same type from your accessor that tries to return grossPays?
 
Stephen Herkins
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know that there are other variable types that would be better for handling currency, but I have to use doubles. I'm not all that familiar with the others.

Here's the error, I now know my method should have included "[]" after double:
Error: (line number of the return statement in getGross here): incompatible types
found: double[]
required: double

I didn't include the exact line number because I am going to change this code.
Thanks for your help.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49411
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

The type of error you are suffering suggests you are trying to return numbers instead of numbers[i].

Have you been told you use all those arrays? That is hardly good design. You ought to have Employee objects which record hours worked, wage rates, etc. Put those objects into an Employee[] array
 
Campbell Ritchie
Sheriff
Pie
Posts: 49411
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the way, in a for loop to traverse an array, you should always use i < myArray.length; as its middle term. Introducing numbers (eg 4) make it error-prone. What will happen if you pass arrays with 3 or 5 members? And passing arrays of numbers rather than an Employee[] array is error-prone. What if the arrays aren't all the same size?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic