By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,496 Members | 1,266 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,496 IT Pros & Developers. It's quick & easy.

need help with a program for school

P: 3
someone check out this program and tell me what im doing wrong please...every time i fix some errors i get even more than before (right now theres 10). note that im a beginner/noob, and that this doesnt work when i click run java application, either. im not sure what exactly i should put in the main method either...

import javax.swing.*;
import java.text.*;

public class Salary
{
public static void main(String[] args)
{
double pay;
pay = getExp1();
pay = getExp2();
pay = getExp3();
finish();
}
public static int getYears()
{
boolean done = false;
int years = 0;
while (!done)
{

String strYears = JOptionPane.showInputDialog(null, "How many years have you worked here?", "Experience", JOptionPane.QUESTION_MESSAGE);

if (strYears == null) finish();

try
{
int years = Integer.parseInt(strYears);
if (years <= 0) throw new NumberFormatException();
else done = true;
}
catch(NumberFormatException e)
{
JOptionPane.showMessageDialog(null, "Your entry was not in the proper format.", "Error", JOptionPane.WARNING_MESSAGE);
}
}

String strHours = JOptionPane.showInputDialog(null, "How many hours have you worked?", "Hours worked", JOptionPane.QUESTION_MESSAGE);
double hours = Double.parseDouble(strHours);

if (years <= 5)
years = getExp1();
else if ((years > 5) && (years <= 10))
years = getExp2();
else if (years > 10)
years = getExp3();
}
public static int getExp1(int years, double hours)
{
double pay;

if (hours > 40)
pay = (16.00 * hours);
else
pay = (12.00 * hours);
return pay;
}
public static int getExp2(int years, double hours)
{
double pay;

if (hours > 40)
pay = (24.00 * hours);
else
pay = (16.00 * hours);
return pay;
}
public static int getExp3(int years, double hours)
{
double pay;

if (hours > 40)
pay = (37.50 * hours);
else
pay = (25.00 * hours);
return pay;
}
public static void output(double pay)
{
DecimalFormat twoDigits = new DecimalFormat("$#0.00");
JOptionPane.showMessageDialog(null, "Your gross pay is " + twoDigits.format(pay), "Gross Pay", JOptionPane.INFORMATION_MESSAGE);
}
public static void finish()
{
System.exit(0);
}
}

and heres the errors:
K:\School Rules!!!!!!!1!\Ch. 4\Salary.java:16: getExp1(int,double) in Salary cannot be applied to ()
pay = getExp1();
^
K:\School Rules!!!!!!!1!\Ch. 4\Salary.java:17: getExp2(int,double) in Salary cannot be applied to ()
pay = getExp2();
^
K:\School Rules!!!!!!!1!\Ch. 4\Salary.java:18: getExp3(int,double) in Salary cannot be applied to ()
pay = getExp3();
^
K:\School Rules!!!!!!!1!\Ch. 4\Salary.java:34: years is already defined in getYears()
int years = Integer.parseInt(strYears);
^
K:\School Rules!!!!!!!1!\Ch. 4\Salary.java:48: getExp1(int,double) in Salary cannot be applied to ()
years = getExp1();
^
K:\School Rules!!!!!!!1!\Ch. 4\Salary.java:50: getExp2(int,double) in Salary cannot be applied to ()
years = getExp2();
^
K:\School Rules!!!!!!!1!\Ch. 4\Salary.java:52: getExp3(int,double) in Salary cannot be applied to ()
years = getExp3();
^
K:\School Rules!!!!!!!1!\Ch. 4\Salary.java:62: possible loss of precision
found : double
required: int
return pay;
^
K:\School Rules!!!!!!!1!\Ch. 4\Salary.java:72: possible loss of precision
found : double
required: int
return pay;
^
K:\School Rules!!!!!!!1!\Ch. 4\Salary.java:82: possible loss of precision
found : double
required: int
return pay;
^
10 errors

Tool completed with exit code 1
Nov 8 '06 #1
Share this Question
Share on Google+
5 Replies


sicarie
Expert Mod 2.5K+
P: 4,677
Trimmed quote:

public static void main(String[] args)
{
double pay;
pay = getExp1();
pay = getExp2();
pay = getExp3();
finish();
}

and heres the errors:
K:\School Rules!!!!!!!1!\Ch. 4\Salary.java:16: getExp1(int,double) in Salary cannot be applied to ()
pay = getExp1();
^
K:\School Rules!!!!!!!1!\Ch. 4\Salary.java:17: getExp2(int,double) in Salary cannot be applied to ()
pay = getExp2();
^
K:\School Rules!!!!!!!1!\Ch. 4\Salary.java:18: getExp3(int,double) in Salary cannot be applied to ()
pay = getExp3();
^
I can tell you that the first three errors are because you pass nothing to the getExp1(), getExp2(), and getExp3() methods, but I am curious about something, are you trying to create just this class (to include in another program), or is this a program all its own? (that will help decide what to do with those statements, if they should be deleted or not...)
Nov 8 '06 #2

P: 3
Trimmed quote:



I can tell you that the first three errors are because you pass nothing to the getExp1(), getExp2(), and getExp3() methods, but I am curious about something, are you trying to create just this class (to include in another program), or is this a program all its own? (that will help decide what to do with those statements, if they should be deleted or not...)
its a program all on its own
Nov 9 '06 #3

sicarie
Expert Mod 2.5K+
P: 4,677
its a program all on its own
Ok, so you are going to have all your input and output in the main portion. It looks like most of the stuff you want in main() is declared right below getYears(), down to getExp1() (and I'm pretty sure you can delete the pay = getExp() lines in main() right now - you already have it declared elsewhere). The double pay needs to be declared outside main().

Try making those changes, see what errors you are getting, if things are making a little more sense. The main() portion of the program is what you want to be executed, everything else is definitions to support and manipulate that main program.

Let me know how that looks and the error messages you get!
Nov 9 '06 #4

P: 3
well nevermind now, i just got my teacher to help me out at the beginning of class today. i only had that error trapping thing for the getYears method and i was supposed to have it for hours too but i couldnt figure it out. so i just turned it in without it. there were also some precision errors i had to fix (changing the ints to doubles and whatnot).

but thanks anyways
Nov 9 '06 #5

sicarie
Expert Mod 2.5K+
P: 4,677
well nevermind now, i just got my teacher to help me out at the beginning of class today. i only had that error trapping thing for the getYears method and i was supposed to have it for hours too but i couldnt figure it out. so i just turned it in without it. there were also some precision errors i had to fix (changing the ints to doubles and whatnot).

but thanks anyways
Yeah, it seemed like you had the idea, and almost all of the code, there were just a few little things here and there.
Nov 9 '06 #6

Post your reply

Sign in to post your reply or Sign up for a free account.