Understaning scope indentifier's
I'm in phase 4 of my program now that I got it to complite. Now I must write 2 more methods with scope identifiers to allow me to total up the gross and net pay from information I obtained from an input file and display it in the corresponding columns. Can anyone pointt me in the direction of finding the information I need to complete my program. My class book do poorly in my opinion in helping me understand this type of method programming. Here is what I started the methods processPay and totalAmounts is what I must use. my program is as follow:
import java.io.*;
import java.util.*;
publicclass Payroll4
{
staticfinaldouble FULL_TIME = 40.0;
staticdouble totalGrossAmount;
staticdouble totalNetAmount;
publicstaticvoid main (String[] args)
throws FileNotFoundException
{
Scanner inFile =new Scanner(new FileReader("payroll.dat"));
StringBuffer employeeName =new StringBuffer();
DoubleClass hourlyRate =new DoubleClass();
DoubleClass hoursWorked =new DoubleClass();
DoubleClass taxRate =new DoubleClass();
DoubleClass grossAmount =new DoubleClass();
DoubleClass netAmount =new DoubleClass();
boolean moreData;
instructions();
reportTitle();
moreData = inputData(inFile, employeeName, hourlyRate, hoursWorked, taxRate);
while(moreData)
{
printEmployeeInfo(employeeName, hourlyRate.getNum(), hoursWorked.getNum(), taxRate.getNum(), grossAmount.getNum(), netAmount.getNum());
moreData =inputData(inFile, employeeName, hourlyRate, hoursWorked, taxRate);
}
inFile.close();
}
publicstaticvoid instructions()
{
System.out.println("Instructions for Payroll Report Program \n");
System.out.println("This program calculates a paycheck for each employess.\n"
+"A text file containing the following information will be created:\n"
+"name, payrate, hours worked, and tax percentage to be deducted.\n");
System.out.println("The program will create a report in columar format showing the \n"
+"employee name, hourly rate, number of hours worked, tax rate,\n"
+"gross pay, and net pay.\n");
System.out.println("After all employees are processed, totals will be displayed,\n"
+"including total gross amount and total net pay.\n");
}
publicstaticvoid reportTitle()
{
System.out.println("Payroll Report\n"
+"\n");
System.out.println("Employee HourlyHoursTaxGrossNet");
System.out.println("NameRateWorkedRateAmountAmount");
System.out.println("--- -- --");
}
publicstaticvoid printEmployeeInfo(StringBuffer employeeName,double hourlyRate,double hoursWorked,double taxRate,double grossAmount,double netAmount)
{
System.out.printf("%-20s%8.2f%8.2f%8.2f%8.2f%8.2f%8.2f%n", employeeName, hourlyRate, hoursWorked, taxRate, grossAmount, netAmount);
if (hoursWorked > FULL_TIME)
System.out.println("OT");
else
System.out.print("");
}
publicstaticboolean inputData(Scanner inFile, StringBuffer employeeName, DoubleClass hourlyRate, DoubleClass hoursWorked, DoubleClass taxRate)
throws FileNotFoundException
{
if(!inFile.hasNext())
returnfalse;
employeeName.setLength(0);
employeeName.append(inFile.nextLine());
hourlyRate.setNum(inFile.nextDouble());
hoursWorked.setNum(inFile.nextDouble());
taxRate.setNum(Double.parseDouble(inFile.nextLine()));
returntrue;
}
publicstaticvoid processPay(double hourlyRate,double hoursWorked,double taxAmount, DoubleClass grossAmount, DoubleClass netAmount)
{
double overtime = 0.0;
grossAmount = hoursWorked * hourlyWorked;
{
if (hoursWorked > FULL_TIME)
overtime = (FULL_TIME - hoursWorked) * 1.5));
grossAmount = grossAmount + overTime;
{
netAmount = (((grossAmount * taxRate) / 100) - grossAmount);
}
publicstaticvoid totalAmounts()
{
String str ="Total";
System.out.printf("%-20s%8.2f%8.2f%n", str, totalGrossAmount, totalNetAmount);
}
}

