This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 557
    
    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: 557
What is grossPays; what is its type? Are you returning that same type from your accessor that tries to return grossPays?


Learning Java using Eclipse on OpenSUSE 11.2
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: 38045
    
  22
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: 38045
    
  22
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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Several questions about this program
 
Similar Threads
Inputfile and getting information out
payroll
Logic Errors
DUE AT MIDNIGHT TONIGHT..1 ERROR..HELP
Not returning a value