aspose file tools*
The moose likes Beginning Java and the fly likes Several questions about this program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Several questions about this program" Watch "Several questions about this program" New topic
Author

Several questions about this program

Stephen Herkins
Greenhorn

Joined: Jan 18, 2011
Posts: 2
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

Joined: Sep 18, 2000
Posts: 562
    
    7

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

Joined: Oct 24, 2010
Posts: 560
What is grossPays; what is its type? Are you returning that same type from your accessor that tries to return grossPays?


Always learning Java, currently using Eclipse on Fedora.
Linux user#: 501795
Stephen Herkins
Greenhorn

Joined: Jan 18, 2011
Posts: 2
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

Joined: Oct 13, 2005
Posts: 38818
    
  23
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

Joined: Oct 13, 2005
Posts: 38818
    
  23
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?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Several questions about this program