I have done all of the coding from 1 week which includes a TestEmployee class where I have to check for integer range, length of string and if its a number or not. I did everything and I can’t find any problem with the methods I have used….But it is giving me error at last two curly braces at the lastline of the program(SAYING WHILE LOOP EXPECTED/REACHED END OF FILE PARSING)…Please help.
Here is my code:
import java.util.Scanner;
import java.lang.Object;
import java.awt.*;
import java.text.*;
public class TestEmployeePayRoll {
public static void main(String[] args)
{
String EmployeeID, FullName, result;
double oursWorked;
int counter = 0;
Scanner input = new Scanner(System.in);
do{
do{
System.out.println("Enter the Employee ID number: "+ " ");
EmployeeID = input.nextLine();
if(EmployeeID.trim().length()>5)
{
System.out.println(" EmployeeID number must be exactly 5: " + " ");
}
}
while(EmployeeID.length() > 5);
System.out.println("Enter the First Name: ");
String FirstName = input.nextLine();
System.out.println("Enter Last Name: "+ " ");
String LastName = input.nextLine();
do
{
System.out.println("Enter the Pay Category: "+ " ");
double PayCategory = input.nextDouble();
Double pay = new Double(PayCategory);
if(pay.isNaN())
{
System.out.println("****Enter a valid Pay Category***");
}
if(!(PayCategory >0 && PayCategory <5))
{
System.out.println("Pay Category must be between 1 and 4");
}
while(PayCategory < 1 || PayCategory > 4);
do
{
System.out.println("Enter the number of hours worked: ");
double HoursWorked = input.nextDouble();
Double hours = new Double(HoursWorked);
if(hours.isNaN())
{
System.out.println("---Enter a valid hours value---");
}
if(!(HoursWorked >1 && HoursWorked <80))
{
System.out.println("---Enter value between 1 and 80---");
}
while(HoursWorked < 1 || HoursWorked > 80);
EmployeePayRoll obj1 = new EmployeePayRoll(FirstName, LastName, EmployeeID, HoursWorked, PayCategory);
DecimalFormat fmt = new DecimalFormat("###,##0.00");
System.out.println("\n-----------------------------------------------------");
System.out.println("\n The pay details for:" + obj1.getName() + "\t\t\t" + "ID:" + EmployeeID);
System.out.println("\n-----------------------------------------------------");
System.out.println("Pay Category: \t\t\t" + obj1.getPayCategory());
System.out.println("Hours Worked: \t\t\t" + obj1.getHoursWorked());
System.out.println("Pay Rate: \t\t\t" + obj1.getPayRate());
System.out.println("Gross Pay: \t\t\t" + "$"+fmt.format(obj1.getGrossPay()));
System.out.println("Tax Payable: \t\t\t" + "$"+fmt.format(obj1.getTaxPayable()));
System.out.println("\t\t\t\t---------");
System.out.println("Net Pay: \t\t\t" + "$" + fmt.format(obj1.getNetPay()));
System.out.println("\n------------------------------------------------------");
System.out.println();
System.out.println("\n +Process another employee? (Y/N)");
result = input.next();
}
while (result.equals("Y")||result.equals("y"));
}} //this two curly giving me errors saying
//reached end of file parsing/while expected...
//It doesn't work if I add or delete curly braces..
Thanks
It seems that line 57 is missing a closing brace directly before it.
while (PayCategory < 1 || PayCategory > 4)After fixing this, you’ll have to worry about the scoping of PayCategory.
Might I also recommend a friendly IDE with reformat capabilities? IntelliJ does a great job at this (as does Eclipse and others).