Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: help with a programing assignment.

  1. #1
    Junior Member
    Join Date
    Apr 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default help with a programing assignment.

    hello i'm new in java and have a problem getting started on a program. which has to follow all of this. Write a Java program to do the following:

    Assume that the company has at most 30 employees. Use two parallel arrays. One will be a two—dimensional array —— a row of
    this array will hold the number of hours worked, hourly pay rate, gross pay, net pay, federal withholding, state withholding, and
    union dues. The second array will be a one—dimensional array of Strings holding the names of the employees. The payroll
    information for the ith name from the array of Strings will be in the ith row of the two—dimensional array.
    This program should read from a file and write to a file.
    Data: Each line will contain a name followed by the number of hours worked and then the pay rate (both real numbers).
    Spaces will separate the fields. Gross pay will be calculated as follows:

    hours <= 40.0 pay rate is used

    40.0 < hours < 50.0 hours above 40.0 and less than 50.0 are paid at one and a half times the pay rate

    50.0 <= hours hours above 50.0 are paid at, twice the pay rate.

    The Federal withholding tax rate is 18% and the state withholding tax rate is 4.5%. The value for union dues is $7.85. .
    Use constants for these and for 30. These may be global
    constants — declared before the main method.
    Use a method when calculating federal withholding and round the answer to the nearest hundredth. Do state withholding the
    same way. Use a method to create a report -— this method will be called after all input and all calculations are done and will
    call the 3 methods specified below.

    a. A method to print heading information including:

    Natural Pine Furniture Company
    Payroll Report

    and column headings for the name, net pay, gross pay, federal tax, state tax, dues, hours, and pay rate -— in that order.

    b. A method to print the detail lines for the employees --matching the headings indicated in a. Single space the
    detail lines.

    c. A method to print a summary line with the totals for net pay, gross pay, dues, federal tax withholding, and state tax
    withholding. (Line should have totals at the bottom of the appropriate columns, or print on separate lines with
    messages.) Also, print a line with a message that contains the number of employees processed.

    after the report has been printed, sort the employees alphabetically and print out the report again. The sort used
    should be a modification of the selection sort handed out. The method specified on page 1 should be used to print out the
    report.
    Next sort the employees in descending order by gross pay and print out the report again. (Again modifying the selection sort
    handed out.) The method specified on page 1 should be used to print out the report.

    This program should be written in a nice form and the output should look nice. Use appropriate methods. The main program
    should consist of method calls. Use one file for all the source code. Use appropriate parameter passing and no nonlocal
    variables.
    Minimal documentation will be accepted for this program. Hand in printed copies of your data file, the source code,
    and the output.
    Data: Form of data is a name, then number of hours (real) and
    then pay rate (real) with spaces separating the fields.
    Last edited by oscar_m; April 13th, 2011 at 07:28 PM.


  2. #2
    Super Moderator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,234
    Thanks
    176
    Thanked 817 Times in 760 Posts
    Blog Entries
    5

    Default Re: help with a programing assignment.

    What have you done? Where are you stuck? You can't expect much just by posting a homework assignment - we won't do this for you, but can help you as you attempt a go at it.

  3. #3
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,465
    My Mood
    Grumpy
    Thanks
    0
    Thanked 158 Times in 149 Posts

    Default Re: help with a programing assignment.

    Anyone who sets an assignment that uses parallel arrays should not be allowed to teach.

  4. #4
    Junior Member
    Join Date
    Apr 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: help with a programing assignment.

    Hi, I actually am having some trouble with this same exact assignment(word for word). Our professor is difficult to say the least... but the trouble I am having is:
    creating a method (report) to read 3 other methods (heading, details, summary). this "report" method has to be ran 3 times during the program. once with info read in from input file, then two other times after being sorted. My problem is that I am having trouble constructing a method that will read the other 3. I first tried (heading)(details) and (summary) as void methods... but then I am having trouble calling those from the (report) method.... I have also tried creating the (report) method as a void method and the other 3(heading)(details)(summary) as String methods.... but I am pretty sure that is the wrong way to go about it as the (detail) method needs to output multiple lines from the arrays.... and as a String method it only return the first line... So I am pretty sure that is the wrong approach. Any help you could give or guidance as to how to appoach this assignment would be great. thanks and have a great day!


    This is the basic setup I have so far.... just outline and not even close to finished just cant get past getting this report method to call.
    import java.io.*;
    import java.text.*;

    public class pinePayroll

    {public static void main (String[]args) throws Exception
    {Scanner inFile = new Scanner (new FileReader("empData.dat"));
    PrintWriter outFile = new PrintWriter ("Payroll.out");
    double [][] data = new double [30][7];
    String [] names = new String [30];
    String str = null;
    String detail = null;
    int n = input(data, names, inFile); //n is name counter 25 total.


    report(outFile,names, n);

    sortName();

    report(outFile, names, n);

    sortPay();

    /report(outFile, names, n);

    outFile.close();
    }
    //************************************************** ****************************************
    public static int input(double [][] data, String [] names, Scanner inFile)
    {int i = 0;
    int m = 0;
    String line;
    StringTokenizer st;
    while (inFile.hasNext() && i < names.length)
    {line = inFile.nextLine();
    st = new StringTokenizer(line);
    m = st.countTokens();
    names [i] = st.nextToken();
    for (int j = 1; j < m-2; j++)
    names [i] = names [i] + " " + st.nextToken();
    data [i][5] = Double.parseDouble(st.nextToken());
    data [i][6] = Double.parseDouble(st.nextToken());
    i++;}
    return i;
    }

    //************************************************** ****************************************
    public static String report(PrintWriter outFile, String[]names, int n)
    {//outFile.println(heading());
    //outFile.println(summary(n));
    return (detail(outFile,names, n));
    outFile.println("\f");}

    //************************************************** ****************************************
    public static String heading()
    {return " NATURAL PINE FURNITURE COMPANY" +
    "\n PAYROLL REPORT" +
    "\n-----------------------------------------------------------------------" +
    "---------------------" +
    "\nNAME" + " " + "NET PAY" + " " + "GROSS PAY" + " " +
    "FEDERAL TAX" + " " + "STATE TAX" + " " + "DUES" + " " +
    "HOURS" + " " + "PAY RATE" +
    "\n-----------------------------------------------------------------------"
    + "---------------------";}
    //************************************************** ****************************************
    public static void detail(PrintWriter outFile, String [] names, int n)
    {for (int i = 0; i < n; i++)
    outFile.println(names[i]);}
    //************************************************** ****************************************
    public static String summary(int n)
    {return "\n-----------------------------------------------------------------------" +
    "---------------------" +
    "\n-----------------------------------------------------------------------" +
    "---------------------" +"\n\nThe total number of names processed is " + n;}

  5. #5
    Member
    Join Date
    Jan 2011
    Posts
    78
    My Mood
    Confused
    Thanks
    23
    Thanked 1 Time in 1 Post

    Default Re: help with a programing assignment.

    When either of you finish this project can you send me your code for it in an email or something? or post it here? I'm new to programming and I'm really curious to look at some code like this that imports information from a file.

Similar Threads

  1. Really need help on assignment
    By coorscollector in forum Java Theory & Questions
    Replies: 2
    Last Post: January 16th, 2012, 05:08 PM
  2. need help with Doubly-Linked list programing in java
    By bulutbey in forum Algorithms & Recursion
    Replies: 3
    Last Post: August 22nd, 2011, 01:51 PM
  3. Help with assignment
    By NPVinny in forum What's Wrong With My Code?
    Replies: 12
    Last Post: July 3rd, 2010, 05:31 PM
  4. need help on an assignment :(
    By gamfreak in forum What's Wrong With My Code?
    Replies: 6
    Last Post: February 23rd, 2010, 03:20 PM
  5. Replies: 1
    Last Post: February 22nd, 2010, 07:20 AM