Anyone know java (having a problem with a monthly payroll system)? - HotUKDeals
We use cookie files to improve site functionality and personalisation. By continuing to use HUKD, you accept our cookie and privacy policy.
Get the HUKD app free at Google Play

Search Error

An error occurred when searching, please try again!

Login / Sign UpSubmit

Anyone know java (having a problem with a monthly payroll system)?

electriclinux Avatar
5y, 11m agoPosted 5 years, 11 months ago
I am having a little problem with some java code and having two arrays (one of name and one of reference number) and parameter passing.
electriclinux Avatar
5y, 11m agoPosted 5 years, 11 months ago
Options

All Comments

(18) Jump to unreadPost a comment
Comments/page:
#1
Post up a link to your code (upload it to pastebin as that'll be easier to read than if you paste it on here). I'm not an expert but two pairs of eyes looking for a bug is better than 1!

Edited By: oldmanhouse on Jan 01, 2011 19:12
#2
http://pastebin.com/qkMqYiUw
I think I might not be declaring the variables right, i am just not sure.
#3
I've downloaded the code and have tried compiling it. The compiler returns several errors, most of which relate to "keyb" package you import at line 7.

I'm not familiar with this package. Are parts of your code from some other source?
#4
The import keyb.InOut; needs mylibrary.jar file. (to allow the user to input data into the program for each salespersons monthly sales and to make a choice in the menu.
#5
Maybe the pseudocode might help.
http://pastebin.com/fuxkhGh4

Edited By: electriclinux on Jan 01, 2011 19:43
#6
ok, Ignoring the keyb.inout related errors, it's coming up with a couple of things:

1. At line 39 you need to change "int message" to "String message" -- compiler is giving an error at line 205 because of this.

2. Also at line 39, you need to remove "static double" from the very start of the line. So it will begin with displayEmployees(.............etc etc)

Try making those alterations and compiling it

Edit: Actually, I'm not sure that's right. It removes the compiler errors but if displayEmployee needs to return a double, then it's going to mess things up later on

Edited By: oldmanhouse on Jan 01, 2011 20:29
#7
Thank you for your help, I am going to try and fix the errors and see what I come up with :)
#8
can u post the compile errors also?
#9
At line 59:

static double averageResult(int MonthlySales[], int NumberOfEmployees)

but then when it's called at line 214:

averageSales = averageResult(spMonthlySales,NumberOfEmployees);

you're passing spMonthlySales which is a double[], rather than an int[] which is what it's expecting as per your definition of averageResult at line 59
#10
It seems to be fine until I want to select one of the options. I don't think it is fair asking for more help just yet. I am going to pound at it and see if I can fix it.
I wish I could leave you guys feedback for your help.

Edited By: electriclinux on Jan 01, 2011 20:58
#11
jayjay, here's the compiler errors for the code as it appears on electriclinux's pastebin entry:


NewClass.java:7: package keyb does not exist
import keyb.InOut;
^

NewClass.java:132: cannot find symbol
symbol : variable InOut
location: class bmc.NewClass
spMonthlySales[empCount] = InOut.readDouble();
^

NewClass.java:144: cannot find symbol
symbol : variable InOut
location: class bmc.NewClass
spMonthlySales[empCount]=InOut.readDouble();
^

NewClass.java:189: cannot find symbol
symbol : variable InOut
location: class bmc.NewClass
menuOption = InOut.readInt();
^

NewClass.java:196: cannot find symbol
symbol : variable InOut
location: class bmc.NewClass
menuOption=InOut.readInt();
^

NewClass.java:205: displayEmployees(int[],java.lang.String[],double[],double[],d
ouble[],double[],int,int,int) in bmc.NewClass cannot be applied to (int,java.lan
g.String,double,double,double,double,int,int,java.lang.String)
displayEmployees(spRefNo[empCount],spName[empCount],spMonthlySales[empCount],spG
rossPay[empCount],spDeductions[empCount],spNetPay[empCount],0,20000,"All Employe
es Details");
^

NewClass.java:209: displayEmployees(int[],java.lang.String[],double[],double[],d
ouble[],double[],int,int,int) in bmc.NewClass cannot be applied to (int[],java.l
ang.String[],double[],double[],double[],double[],int,int,java.lang.String)
displayEmployees(spRefNo,spName,spMonthlySales,spGrossPay,spDeductions,spNetPay,
10000,20000, "Employees whose monthly sales are £10,000 or above");
^

NewClass.java:214: averageResult(int[],int) in bmc.NewClass cannot be applied to
(double[],int)
averageSales = averageResult(spMonthlySales,NumberOfEmployees);
^

NewClass.java:215: displayEmployees(int[],java.lang.String[],double[],double[],d
ouble[],double[],int,int,int) in bmc.NewClass cannot be applied to (int[],java.l
ang.String[],double[],double[],double[],double[],double,java.lang.String)
displayEmployees(spRefNo,spName,spMonthlySales,spGrossPay,spDeductions,spNetPay,
averageSales,
^

NewClass.java:225: incompatible types
found : double
required: boolean
if (spMonthlySales[empCount] = highestSales)
^

10 errors


keyb.InOut errors are appearing for me as I haven't compiled it with the right package so I guess they won't be appearing for electriclinux and therefore aren't a problem.

Good luck with it OP, I'll keep having a look at it as I've nothing to do and it's good practise!! :p

Edited By: oldmanhouse on Jan 01, 2011 21:02
#12
Thanks, i agree with you that

static double should be removed from displayEmployees , and it won't cause any issues in it's current form, since that method does not ever return a value anyway. It just outputs the result and returns

and line 225, shouldn't that be

if (spMonthlySales[empCount] == highestSales)


Edited By: jayjayuk1234 on Jan 01, 2011 21:14
#13
The error at line 205 occurs because it is expecting arrays but you provide it's being provided with one single value (e.g spRefNo[empCount] -- which is refering to one value in the array, rather than all of them which I expect is what you intended. You just need to remove "[empCount]" from each of the parameters on line 205 )



Edited By: oldmanhouse on Jan 01, 2011 21:26
#14
Cheers, it is hard to try and convey with just a message online but I truly appreciate the help.
#15
electriclinux
Cheers, it is hard to try and convey with just a message online but I truly appreciate the help.


No problem! :)

I've eliminated all the compiler errors which I've been getting (except the keyb ones, but I'm just ignoring those).

Line 225: Solution given by jayjay -- just add an extra "=" as you're assigning when just using one and you're actually trying to compare the two variables.

Line 215: Two problems here. One is that you're missing a parameter and the other is that one is the wrong type.
The missing parameter goes between "averageSales" and "Employees whose monthly sales are below the average" -- you've called this particular parameter "highValue" so I don't know if that means anything to you? In my revised code, I've just put a parameter called "someInt" in there so it will compile without error.
The parameter (averageSales) which is the wrong type is spNetPay. The type you're using on line 215 is double and it needs to be Int. I've fixed this by converting averageSales to Int type -- the new variable is called averageSalesAsInt

Line 214: This problem is down to the wrong type being used again. This time is was expecting an array of Ints but was getting an array of doubles. Further up in the code, I've written a for loop which converts the list of doubles to ints (line 65 in my revised code).

Line 209: Simple problem here which I mentioned in post #6 -- you accidentally put "int" as the last parameter when it should be "string" -- as it's for the message.

Line 205: See post #13

Here's my revised code which compiles for me: http://pastebin.com/iNfB6fgm

I'm going to take back my 2nd suggestion in post #6 as I don't think its right. If you remove "static double", it gets rid of the compiler errors but it shouldn't as it's not solving the problems. I suspect things would go wrong when you actually ran the code. Having said that, jayjay is correct in saying there's no return value so there's no need to have it say "static double" -- it should be "static void" if there's no return value. The compiler doesn't complain though so I just left it as "static double", but it may cause you problems so the above is something to keep in mind....

I hope my revised code helps you but as it's only one part of your program, it might not agree with the other pieces of code you've written. My solutions aren't very elegant but they seemed to work!!

That's all from me, better do some of my own work lol!!
#16
Hi I am just having a little bit of a problem with line 51,80,87 and 254.
http://pastebin.com/sbFWBfth
#17
Compiling it, I'm only getting one error which is on line 254. I'm not all that familiar with switch statements but I think the problem is you have case 5 inside case 4.

You need to move

case 5:
System.exit();


to outside the for loop which case 4 is running. So cut-paste it to line 263 above where you have a brace commented with "switch statement".

Also -- I think it's supposed to be System.exit(0); rather than just () .... the number signifies the type of exit you are making. 0 being a normal exit, 1 indicating a problem. In practise, it doesn't matter which you use (as far as I know) so just use System.exit(0);

I'm not seeing any compiler errors with 51, 80 and 87 -- what problems are you having with them? I see that they are the lines of code I added so I guess you're having problems with them at runtime rather than when compiling?

Edited By: oldmanhouse on Jan 02, 2011 18:20
#18
electriclinux
Hi I am just having a little bit of a problem with line 51,80,87 and 254.
http://pastebin.com/sbFWBfth


You aren't doing yourself any favours everytime you get a problem you need to post your compiler errors :)

Post a Comment

You don't need an account to leave a comment. Just enter your email address. We'll keep it private.

...OR log in with your social account

...OR comment using your social account

Thanks for your comment! Keep it up!
We just need to have a quick look and it will be live soon.
The community is happy to hear your opinion! Keep contributing!