import java.util.Scanner; //util/scannerclass
import java.io.*; //needed for files
public class Lab4
{
public static void main(String[]args) throws FileNotFoundException
{
double gross, //gross pay
deductions, //deduction
net, //net pay
hours, //hours worked
rate, //rate per hour
totalgross = 0, //total gross paid out
totalnet=0, //total net pay paid out
overtime=0,
overtimehours=0,
bonus=0,
regularpay,
overtimepay,
mdeductions;
int empId, //employee id
filenumber,
department;
String enter; //person of input's name
Scanner input = new Scanner(System.in); //input new scanner
{
if (filenumber==1)
Scanner inPayrollFile = new Scanner(new FileReader("Lab4Input1.txt"));
// assigns "inPayrollFile" to input file
PrintWriter outPayrollFile = new PrintWriter("Lab4Output1.txt");
// assigns "outPayrollFile" to output file
else
Scanner inPayrollFile = new Scanner(new FileReader("Lab4Input2.txt"));
// assigns "inPayrollFile" to input file
PrintWriter outPayrollFile = new PrintWriter("Lab4Output2.txt");
// assigns "outPayrollFile" to output file\
}
final String HEADING1= "Id# hours OT Bonus rate gross deduc net Department#"; //example of a defined constant
System.out.println();
System.out.print("What is your name? >"); //employee amount
enter = input.nextLine();
outPayrollFile.println (HEADING1);
while(inPayrollFile.hasNext())
{
empId = inPayrollFile.nextInt();
hours = inPayrollFile.nextDouble();
rate = inPayrollFile.nextDouble();
department = inPayrollFile.nextInt();
gross=getregularpay(hours, rate);
overtime=getovertimedpay(rate, hours);
regularpay=(gross+overtime);
deductions=getdeductions(gross);
bonus=getbonuspay(hours, gross, department);
net=(regularpay+bonus-deductions); //calculate net pay
System.out.println();
outPayrollFile.println();
outPayrollFile.print("#" + empId);
outPayrollFile.printf("$%7.2f ",hours);
outPayrollFile.printf("$%7.2f ",overtime);
outPayrollFile.printf("$%7.2f ",rate);
outPayrollFile.printf("$%7.2f ",gross);
outPayrollFile.printf("$%7.2f ",deductions);
outPayrollFile.printf("$%7.2f%n",net);
//,hours,rate,gross,deductions,net); //output New Balance using num format outPayrollFile.printf("$%7.2f%n",deductions); //Output total interest outPayrollFile.printf("$%7.2f%n",net); //displays overdraft fee
System.out.println();
totalgross=(totalgross+regularpay);
totalnet=(totalnet+net);
}
outPayrollFile.println();
outPayrollFile.println();
outPayrollFile.println();
outPayrollFile.printf(" $%7.2f%n ",totalgross);
outPayrollFile.printf(" $%7.2f%n ",totalnet);
System.out.println();
System.out.println();
System.out.println();
outPayrollFile.print("Program completed, thank you " + enter);
outPayrollFile.close();
} //end static
public static double getregularpay(double hours, double rate)
{
double regularpay;
if(hours<=40)
regularpay=rate*hours; //compute gross
else
regularpay=40*rate;
return regularpay;
}
public static double getovertimedpay(double rate, double hours)
{
double overtimepay;
if(hours>40)
overtimepay=(hours-40)*rate*1.5;
else
overtimepay=0;
return overtimepay;
}
public static double getdeductions(double gross)
{
double mdeductions;
{
if(gross<=500) //if statement
mdeductions=.20*(gross);
else if(gross<=1000)
mdeductions=(.25*gross+100);
else
mdeductions=(.30*gross+225);
}
Math.round(mdeductions*10/10);
return mdeductions;
}
public static double getbonuspay(double hours, double gross, int department)
{
double bonuss;
if(department==25)
if (hours>=40)
bonuss=(gross*1.10);
else
bonuss=(gross*1.05);
else
bonuss=0;
return bonuss;
}
} //end class
Errors Are:
Lab4.java:54: error: not a statement
Scanner inPayrollFile = new Scanner(new FileReader("Lab4Input1.txt"));
^
Lab4.java:54: error: ';' expected
Scanner inPayrollFile = new Scanner(new FileReader("Lab4Input1.txt"));
^
Lab4.java:60: error: 'else' without 'if'
else
^
This post was edited by Archer on Dec 3 2012 10:01am