• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Several questions about this program

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Bartender
Posts: 612
7
Mac OS X Python
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 563
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic