need help with a program for school

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Lockwood
    New Member
    • Nov 2006
    • 3

    #1

    need help with a program for school

    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.sho wInputDialog(nu ll, "How many years have you worked here?", "Experience ", JOptionPane.QUE STION_MESSAGE);

    if (strYears == null) finish();

    try
    {
    int years = Integer.parseIn t(strYears);
    if (years <= 0) throw new NumberFormatExc eption();
    else done = true;
    }
    catch(NumberFor matException e)
    {
    JOptionPane.sho wMessageDialog( null, "Your entry was not in the proper format.", "Error", JOptionPane.WAR NING_MESSAGE);
    }
    }

    String strHours = JOptionPane.sho wInputDialog(nu ll, "How many hours have you worked?", "Hours worked", JOptionPane.QUE STION_MESSAGE);
    double hours = Double.parseDou ble(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.sho wMessageDialog( null, "Your gross pay is " + twoDigits.forma t(pay), "Gross Pay", JOptionPane.INF ORMATION_MESSAG E);
    }
    public static void finish()
    {
    System.exit(0);
    }
    }

    and heres the errors:
    K:\School Rules!!!!!!!1!\ Ch. 4\Salary.java:1 6: getExp1(int,dou ble) in Salary cannot be applied to ()
    pay = getExp1();
    ^
    K:\School Rules!!!!!!!1!\ Ch. 4\Salary.java:1 7: getExp2(int,dou ble) in Salary cannot be applied to ()
    pay = getExp2();
    ^
    K:\School Rules!!!!!!!1!\ Ch. 4\Salary.java:1 8: getExp3(int,dou ble) in Salary cannot be applied to ()
    pay = getExp3();
    ^
    K:\School Rules!!!!!!!1!\ Ch. 4\Salary.java:3 4: years is already defined in getYears()
    int years = Integer.parseIn t(strYears);
    ^
    K:\School Rules!!!!!!!1!\ Ch. 4\Salary.java:4 8: getExp1(int,dou ble) in Salary cannot be applied to ()
    years = getExp1();
    ^
    K:\School Rules!!!!!!!1!\ Ch. 4\Salary.java:5 0: getExp2(int,dou ble) in Salary cannot be applied to ()
    years = getExp2();
    ^
    K:\School Rules!!!!!!!1!\ Ch. 4\Salary.java:5 2: getExp3(int,dou ble) in Salary cannot be applied to ()
    years = getExp3();
    ^
    K:\School Rules!!!!!!!1!\ Ch. 4\Salary.java:6 2: possible loss of precision
    found : double
    required: int
    return pay;
    ^
    K:\School Rules!!!!!!!1!\ Ch. 4\Salary.java:7 2: possible loss of precision
    found : double
    required: int
    return pay;
    ^
    K:\School Rules!!!!!!!1!\ Ch. 4\Salary.java:8 2: possible loss of precision
    found : double
    required: int
    return pay;
    ^
    10 errors

    Tool completed with exit code 1
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #2
    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:1 6: getExp1(int,dou ble) in Salary cannot be applied to ()
    pay = getExp1();
    ^
    K:\School Rules!!!!!!!1!\ Ch. 4\Salary.java:1 7: getExp2(int,dou ble) in Salary cannot be applied to ()
    pay = getExp2();
    ^
    K:\School Rules!!!!!!!1!\ Ch. 4\Salary.java:1 8: getExp3(int,dou ble) 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...)

    Comment

    • Lockwood
      New Member
      • Nov 2006
      • 3

      #3
      Originally posted by sicarie
      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

      Comment

      • sicarie
        Recognized Expert Specialist
        • Nov 2006
        • 4677

        #4
        Originally posted by Lockwood
        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!

        Comment

        • Lockwood
          New Member
          • Nov 2006
          • 3

          #5
          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

          Comment

          • sicarie
            Recognized Expert Specialist
            • Nov 2006
            • 4677

            #6
            Originally posted by Lockwood
            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.

            Comment

            Working...