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.
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.
Re: help with a programing assignment.
Anyone who sets an assignment that uses parallel arrays should not be allowed to teach.
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;}
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.