Results 1 to 3 of 3
  1. #1
    eddyb5 is offline Member
    Join Date
    Jun 2011
    Posts
    2
    Rep Power
    0

    Default Payroll program.. School.. Help Please!

    Hello there,
    I have this code due tomorrow, and i'm literally stumped and swamped. My brain hurts.
    Any help will be much appreciated..
    This is what I have.

    // The "Payroll" class.
    import java.awt.*;
    import hsa.Console;
    import java.text.*;


    public class Payroll
    {
    //global variables
    static Console c; // The output console
    static int x, y, employees;
    static double wage[] = new double [1001];
    static double hours[] = new double [1001];
    static String name[] = new String [1001];
    static String payperiod;
    public static void main (String[] args)
    {
    c = new Console ();
    int choice;
    do
    {
    c.clear ();
    c.println ("Welcome to the Payroll program!"); //main menu + options
    c.println ("-------------------------------");
    c.println ("1. Start a new payroll");
    c.println ("2. Display current payroll (check payroll)");
    c.println ("3. Edit current payroll");
    c.println ("4. Exit Program");
    c.println ("-----------------------");
    c.println ("What is your choice?");
    choice = c.readInt ();
    if (choice == 1)
    newpayroll ();
    if (choice == 2)
    payrollcheck ();
    if (choice == 3)
    payrollcheck (); // (only until the edit method is created)
    if (choice == 4)
    {
    c.println ("Thanks for using the program, bye!");
    }
    }
    while (choice != 4);
    }


    public static void newpayroll () //method 1
    {
    int x;
    c.clear ();
    c.println ("How many employees do you wish to do a payroll for?");
    employees = c.readInt();
    for (x = 1 ; x <= employees ; x++)

    {
    c.clear ();
    c.println ("Employee " + x);
    c.println ("Please enter the name of this employee ");
    name [x] = c.readLine ();
    c.println ("What is " + name [x] + "'s hourly wage?");
    wage [x] = c.readDouble ();
    c.println ("How many hours did " + name [x] + " work? ");
    hours [x] = c.readDouble ();

    }
    }


    public static void payrollcheck () //method 2
    {
    DecimalFormat fc = new DecimalFormat ("$###,###,###,###,###,###,###.00");
    double grosspay, netpay, totaldeductions, cpp, ei, tax;
    c.clear ();
    sort ();
    c.println (" This weeks payroll ");
    c.println ("-------------------------------------------------------");
    for (x = 1 ; x <= employees ; x++);
    grosspay = wage [x] * hours [x];
    cpp = grosspay * 0.00495;
    ei = grosspay * 0.00178;
    tax = grosspay * 0.20;
    totaldeductions = cpp + ei + tax;
    netpay = grosspay - totaldeductions;
    {
    c.println (name [x] + "'s payroll data:");
    c.println ("Gross pay: " + fc.format (grosspay));
    c.println ("CPP: " + fc.format (cpp));
    c.println ("EI: " + fc.format (ei));
    c.println ("Tax: " + fc.format (tax));
    c.println ("Total Deductions: " + fc.format (totaldeductions));
    c.println ("Net pay: " + fc.format (netpay));


    }
    pause ();
    }


    //start sort method//
    public static void sort ()
    {
    //variables//
    double tempa, tempp;
    String tempn;
    //main loop//
    for (y = 1 ; y <= 10 ; y++)
    {
    for (x = 1 ; x <= 10 - y ; x++)
    {
    //if statement//
    if (wage [x] > wage [x + 1])
    {
    tempn = name [x];
    tempa = wage [x];
    tempp = hours [x];
    name [x] = name [x + 1];
    wage [x] = wage [x + 1];
    hours [x] = hours [x + 1];
    name [x + 1] = tempn;
    wage [x + 1] = tempa;
    hours [x + 1] = tempp;
    }
    }
    }
    } //ending sort method//


    //starting pause method//
    public static void pause ()
    {
    //variables//
    char pause;
    c.print ("Press enter to continue ");
    pause = c.readChar ();
    } //ending pause method//
    }

    I need to still add another method, which allows the user to modify the data that they have already entered. Again, any help will be much appreciated.
    Thanks, Ed

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Quote Originally Posted by eddyb5 View Post
    Hello there,
    I have this code due tomorrow, and i'm literally stumped and swamped. My brain hurts.
    Welcome to the forum. Just for future references please understand that this is not a code writing service, but we would be more than happy to try to help you understand Java better. With that in mind a few suggestions, the first being it would be best to leave mention of due date out of the discussion as it's not our concern or germane to your code problem.


    This is what I have....
    You'll want to edit your original post and add code tags so we can read your code and understand it. To do this, place the tag

    [code]

    above your code block and the tag

    [/code]

    below your code block.


    I need to still add another method, which allows the user to modify the data that they have already entered.
    So what have you tried? You will learn more and we will know your deficiencies if we can see your attempt first and any errors that it might produce.

    Best of luck and again welcome.

  3. #3
    eddyb5 is offline Member
    Join Date
    Jun 2011
    Posts
    2
    Rep Power
    0

    Default

    Sorry for my original post, I was a tad bit stressed.

    As of right now, the only issues that I am having is that when I run the methods to add or delete data, the program finishes, rather then returning to the main menu.. In my other methods, my pause (); accomplishes this.. But I'm not exactly sure why these methods won't do the same thing.

    Thanks in advance for any help.

    Java Code:
    // The "Payroll" class.
    import java.awt.*;
    import hsa.Console;
    import java.text.*;
    
    
    public class Payroll
    {
        //global variables
        static Console c;           // The output console
        static int x, y, employees, addchoice;
        static double wage[] = new double [1001];
        static double hours[] = new double [1001];
        static String name[] = new String [1001];
        static String payperiod;
        public static void main (String[] args)
        {
            c = new Console ();
            int choice;
            do
            {
                do
                {
                   
                    c.clear ();
                    c.println ("Welcome to the Payroll program!"); //main menu + options
                    c.println ("-------------------------------");
                    c.println ("1.  Start a new payroll");
                    c.println ("2.  Display current payroll (check payroll)");
                    c.println ("3.  Edit current payroll");
                    c.println ("4.  Add an employee to the current payroll");
                    c.println ("5.  Delete an employee off the current payroll");
                    c.println ("6.  Exit Program");
                    c.println ("-----------------------");
                    c.println ("What is your choice?");
                    choice = c.readInt ();
                }
                while ((choice <= 0) || (choice >= 7));
                if (choice == 1)
                    newpayroll ();
                if (choice == 2)
                    payrollcheck ();
                if (choice == 3)
                    modifypayroll ();
                if (choice == 4)
                    addemployee ();
                if (choice == 5)
                    deleteemployee ();
                    if (choice == 5)
                    {
                        c.println ("Thanks for using the program, bye!");
                    }
            }
            while (choice != 4);
        }
    
    
        public static void newpayroll ()  //method 1
        {
            int x;
            c.clear ();
            c.println ("How many employees do you wish to do a payroll for?");
            employees = c.readInt ();
            for (x = 1 ; x <= employees ; x++)
            {
                c.clear ();
                c.println ("Employee " + x);
                c.println ("Please enter the name of this employee ");
                name [x] = c.readLine ();
                c.println ("What is " + name [x] + "'s hourly wage?");
                wage [x] = c.readDouble ();
                c.println ("How many hours did " + name [x] + " work? ");
                hours [x] = c.readDouble ();
    
            }
        }
    
    
        public static void payrollcheck ()  //method 2
        {
            DecimalFormat fc = new DecimalFormat ("$###,###,###,###,###,###,###.00");
            double grosspay, netpay, totaldeductions, cpp, ei, tax;
            c.clear ();
            sort ();
            c.println ("            This weeks payroll            ");
            c.println ("-------------------------------------------------------");
            for (x = 1 ; x <= employees ; x++)
            {
                grosspay = wage [x] * hours [x];
                cpp = grosspay * 0.00495;
                ei = grosspay * 0.00178;
                tax = grosspay * 0.20;
                totaldeductions = cpp + ei + tax;
                netpay = grosspay - totaldeductions;
                c.println ("\n" + name [x] + "'s payroll data:");
                c.println ("Gross pay: " + fc.format (grosspay));
                c.println ("CPP: " + fc.format (cpp));
                c.println ("EI: " + fc.format (ei));
                c.println ("Tax: " + fc.format (tax));
                c.println ("Total Deductions: " + fc.format (totaldeductions));
                c.println ("Net pay: " + fc.format (netpay));
            }
            pause ();
        }
        public static void modifypayroll ()
        {
            c.clear ();
            int flag;
            String modifyemployee;
            boolean found;
            flag = 0;
            found = false;
            c.print ("What is the employee's name you want to modify? ");
            modifyemployee = c.readLine ();
            for (x = 1 ; x <= employees ; x++)
            {
                if (modifyemployee.equalsIgnoreCase (name [x]))
                {
                    flag = x;
                    found = true;
                }
            }
            if (found == false)
            {
                c.println ("That employee is not found");
                pause ();
            }
            else
            {
                c.println ("The Players previous data is:");
                c.println ("--------------------------------------------------------------------------------");
                c.println ("NAME\t\t\tWAGE\t\tHOURS\t\t");
                c.println ("--------------------------------------------------------------------------------");
                c.println (name [flag] + "\t\t\t" + wage [flag] + "\t \t" + hours [flag]);
                c.println ("--------------------------------------------------------------------------------");
                c.print ("What is the employee's new name? ");
                name [flag] = c.readLine ();
                c.print ("What is the employee's new wage? ");
                wage [flag] = c.readDouble ();
                c.print ("What is the employee's new hours worked? ");
                hours [flag] = c.readDouble ();
            }
        }
        public static void addemployee ()
        {
            c.clear ();
            c.print ("How many players do you want to add? ");
            addchoice = c.readInt ();
            for (x = 1 ; x <= addchoice ; x++)
            {
                c.clear ();
                employees++;
                c.println ("Employee " + employees);
                c.print ("What is the employee's name? ");
                name [employees] = c.readLine ();
                c.print ("What is the employee's wage? ");
                wage [employees] = c.readDouble ();
                c.print ("What is the players position? ");
                hours [employees] = c.readDouble ();
            }
        }
            public static void deleteemployee ()
        {
            c.clear ();
            int flag, deleteyn;
            String deleteemployee;
            boolean found;
            flag = 0;
            found = false;
            c.print ("What is the player's name you want to delete? ");
            deleteemployee = c.readLine ();
            for (x = 1 ; x <= employees ; x++)
            {
                if (deleteemployee.equalsIgnoreCase (name [x]))
                {
                    flag = x;
                    found = true;
                }
            }
            if (found == false)
            {
                c.println ("That employee is not found");
                pause ();
            }
            else
            {
                c.clear ();
                c.println ("The employee's data is:");
                c.println ("--------------------------------------------------------------------------------");
                c.println ("NAME\t\t\tWAGE\t\tHOURS WORKED\t\t");
                c.println ("--------------------------------------------------------------------------------");
                c.println (name [flag] + "\t\t\t" + wage [flag] + "\t\t" + hours [flag]);
                c.println ("--------------------------------------------------------------------------------");
                do
                {
                    c.println ("1. Yes");
                    c.println ("2. No");
                    c.print ("Are you sure you want to delete this player? ");
                    deleteyn = c.readInt ();
                    pause ();
                }
                while ((deleteyn <= 0) || (deleteyn >= 3));
                if (deleteyn == 1)
                {
                    for (x = flag ; x <= employees - 1 ; x++)
                    {
                        name [x] = name [x + 1];
                        wage [x] = wage [x + 1];
                        hours [x] = hours [x + 1];
                    }
                    employees--;
                }
            }
        }
    
    
        //start sort method//
        public static void sort ()
        {
            //variables//
            double tempa, tempp;
            String tempn;
            //main loop//
            for (y = 1 ; y <= employees ; y++)
            {
                for (x = 1 ; x <= employees - y ; x++)
                {
                    //if statement//
                    if (wage [x] > wage [x + 1])
                    {
                        tempn = name [x];
                        tempa = wage [x];
                        tempp = hours [x];
                        name [x] = name [x + 1];
                        wage [x] = wage [x + 1];
                        hours [x] = hours [x + 1];
                        name [x + 1] = tempn;
                        wage [x + 1] = tempa;
                        hours [x + 1] = tempp;
                    }
                }
            }
        } //ending sort method//
    
    
        //starting pause method//
        public static void pause ()
        {
            //variables//
            char pause;
            c.print ("Press enter to continue ");
            pause = c.readChar ();
        } //ending pause method//
    }

Similar Threads

  1. payroll program 2
    By joshwey in forum New To Java
    Replies: 13
    Last Post: 05-13-2011, 09:27 AM
  2. Payroll program
    By bigley04 in forum Eclipse
    Replies: 7
    Last Post: 12-06-2010, 04:57 PM
  3. Need help ASAP with Payroll Program Part 2
    By arrech326 in forum New To Java
    Replies: 10
    Last Post: 11-17-2009, 10:17 PM
  4. Payroll Program exits at wrong time
    By jsand2 in forum Java Applets
    Replies: 13
    Last Post: 01-26-2009, 03:10 AM
  5. Beginner Needs Help w/ Program for School
    By badness in forum New To Java
    Replies: 2
    Last Post: 11-24-2007, 07:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •