So I am taking this Java Programming class for my last 4 credits of my bachelor's degree and i'm also full-time in beauty school. I have put about 20 Hours into this assignment and I CANNOT get it . Someone please help! There is a .dat file that was given to us, not sure how to upload it here? I could send it through e-mail if you can help me. Any help would be greatly appreciated! This was due yesterday and I was given an extension until tomorrow. Here is the problem given to us and here is what I have written..
Here is the problem definition.
Your employer needs a program that calculates and prints the monthly paycheck for an employee. The net pay is calculated after taking the following deductions:
Federal Income Tax 15%
State Tax 3.5%
Social Security Tax 5.75%
Medicare/Medicaid Tax 2.75%
Pension Plan 5%
Health Insurance $75.00
Your program will read the data from a file, paycheck.dat, that is attached to this assignment.
The data file contains the following data: first name, last name, annual salary (the company pays it's staff every month; so there are 12 pay periods in a year)
The format for the data file is:
Allison Neilds 92950.00
Please note: In a normal business, you would have multiple records in your data file one for each employee; but since we have not covered loops yet we can only read one employee... it is a start!
The output will contain: first name, last name, monthly gross pay, federal taxes, state taxes, SSN taxes, Medicare/Medicaid Taxes, Pension, Health Insurance, Net Pay
A sample output follows:
Allison Neilds 7745.83 1161.88 271.10 445.39 213.01 387.29 75.00 5192.17
Some Processing Requirements:
- use the Scanner/FileReader or Scanner/BufferedReader to read the data into your program.
- put the paycheck.dat file in the directory of where your program is located and use a relative pathname to reference the file in the program.
- use the PrintWriter to create the output file, name it paycheckout.dat.- use a relative pathname to reference the output file.
- String.format to format the the output to 2 decimal places.
- remember the output is producing a data file, not a report do not use $ or commas
- Do not use magic numbers! A magic number is a numeric constant embedded in code, without a constant definition. Any number except -1, 0, and 1 is considered magic.
- use the try/catch statement to catch the FileNotFoundException and IOException
Click on the link below to submit for grading, submit the unit6_YourLastName.java program.
Be sure to put your name in the comment box.
DO NOT email the assignment to me.
/* Program Name: unit6_mihans.java
*/
import java.io.*;
import java.util.*;
public class unit6_mihans
public static void main(String args[]) throws IOException
String firstName;
String lastName;
double annualPay;
double monthlyPay;
double federalTax;
double stateTax;
double socialSecurity;
double medicareMedicaid;
double pensionPlan;
double healthInsurance;
double netPay;
Scanner inFile = new Scanner(new FileReader("paycheck.dat"));
while (inFile.has Next())
{
String firstName=inFile,next();
String lastName=inFile.next();
annualPay=inFile.nextDouble();
if (inFile.hasNextDouble())
{
monthlyPay= annualPay/12;
federalTax= monthlyPay *.15;
stateTax= monthlyPay * .035;
socialSecurity= monthlyPay * 5.75;
medicareMedicaid= monthlyPay * 2.75;
pensionPlan= monthlyPay * .05;
healthInsurance= 75.00;
netPay= monthlyPay - federalTax - stateTax - socialSecurity - medicareMedicaid - pensionPlan - healthInsurance;
String outputString=String.format("%25s\n",lastName +","+firstName) + String.format("%25s %7.2f%n",+monthlyPay","+federalTax","+stateTax","+ socialSecurity","+medicareMedicaid","+pensionPlan" ,"+healthInsurance","+netPay);
PrintWriter pw = new PrintWriter(System.out, true);
pw.println(outputString);
}
catch (FileNotFoundException e)
{
outputString=String.format("%25s\n",lastName + "," +firstName)
+ String.format
System.out.println(outputString);
}
String filename = ("paycheck.dat");
try
{
new File(filename).createNewFile();
}
catch (IOException e) {
System.out.println("Unable to create "+filename+" : "+e.getMessage());
}
inFile.close();
}