CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2010
    Posts
    1

    Easy answer new to Java. "reached end of file while parsing"

    I am very new to Java and need to complete this for some homework. The File runs just will not compile because of "week3day5.java:40: reached end of file while parsing"
    Here is the code:

    Code:
    package whalenpaymachine;
    
    //File: week3day5.java
    
    import java.text.NumberFormat;
    import java.util.Scanner;
    
    public class week3day5 {
    
    public static void main(String[] args) {
    System.out.println("\nEmployee Payment Calculator\n");
    // Input Section
    Scanner in = new Scanner(System.in);
    String name;
    double rate;
    double hours;
    
    // Employee Name
    do {
    //needed for scanner class
    Scanner kb = new Scanner(System.in);
    
    // get users string
    System.out.print("Enter the employee name: ");
    empName = kb.nextLine();
    if ("stop".equalsIgnoreCase(empName)) {
    // Exit the loop because the user wants to quit
    break;
        }
    // Employee hourly rate:
    System.out.print("Enter the hourly rate: ");
    rate = Double.parseDouble(in.nextLine());
    // Employee hours worked:
    System.out.print("Enter the hours worked:");
    hours = Double.parseDouble(in.nextLine());
    // Output Section
    System.out.println("\nEmployee: " + name);
    NumberFormat nf = NumberFormat.getCurrencyInstance();
    System.out.println(
    "\nEarned a weekly Pay of: " + nf.format(rate * hours));
    Error message:

    "Compiling 1 source file to C:\Users\Daboss\Desktop\IT 215 Java\Compiled\Whalen Pay Machine\build\classes
    C:\Users\Daboss\Desktop\IT 215 Java\Compiled\Whalen Pay Machine\src\whalenpaymachine\week3day5.java:40: reached end of file while parsing
    "\nEarned a weekly Pay of: " + nf.format(rate * hours));
    C:\Users\Daboss\Desktop\IT 215 Java\Compiled\Whalen Pay Machine\src\whalenpaymachine\week3day5.java:41: reached end of file while parsing"


    Any help would be appreciated and an explanation so i could learn from my mistakes. Thank you very much!

    I do understand I need to add } somewhere I just do not understand where or why!

  2. #2
    Join Date
    Oct 2008
    Posts
    77

    Re: Easy answer new to Java. "reached end of file while parsing"

    Java compiler is simply saying code file has ended and that it expects to see more characters.

    All opened brackets need to be closed, I think you are missing three.

  3. #3
    Join Date
    Jun 2007
    Location
    Aurora CO USA
    Posts
    137

    Re: Easy answer new to Java. "reached end of file while parsing"

    This is why you'll see code indented. It makes finding missing end brackets a bit easier. Take a look:
    Code:
    public class week3day5 
    {
    
        public static void main(String[] args) 
        {
            System.out.println("\nEmployee Payment Calculator\n");
            // Input Section
            Scanner in = new Scanner(System.in);
            String name;
            double rate;
            double hours;
    
            // Employee Name
            do 
            {
                //needed for scanner class
                Scanner kb = new Scanner(System.in);
    
                // get users string
                System.out.print("Enter the employee name: ");
                empName = kb.nextLine();
                if ("stop".equalsIgnoreCase(empName)) 
                {
                    // Exit the loop because the user wants to quit
                    break;
                }
                // Employee hourly rate:
                System.out.print("Enter the hourly rate: ");
                rate = Double.parseDouble(in.nextLine());
                // Employee hours worked:
                System.out.print("Enter the hours worked:");
                hours = Double.parseDouble(in.nextLine());
                // Output Section
                System.out.println("\nEmployee: " + name);
                NumberFormat nf = NumberFormat.getCurrencyInstance();
                System.out.println("\nEarned a weekly Pay of: " + nf.format(rate * hours));
    Can you see where they should be now?

    There should be 3 at the end of the file. Once you place them, I think you'll find you have another problem, there seems to be some missing code for the do statement.

    Also, watch your variable names. You seem to be calling something name in one place and empName in others.

    Give this a try and let us know how it goes.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured