Results 1 to 13 of 13
  1. #1
    gusten is offline Member
    Join Date
    Jul 2013
    Posts
    19
    Rep Power
    0

    Default A couple errors in program

    Hey guys I have been working on this program and I have a few errors that I'm not sure how to get rid of...

    Lab01

    Java Code:
    package lab01;
    
    import java.text.DecimalFormat;
    import java.util.Scanner;
    
    public class Lab01 {
    
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args)
            // TODO code application logic here
        {
            try (Scanner scan = new Scanner(System.in)) {
                Employee e1, e2, e3, e4;
                String name;
                
                System.out.print("Enter name of 1st Employee: ");
                name = scan.next();
                e1 = new Employee(name);
                
                System.out.println("Employee count is "+getCount());
                
                System.out.print("Enter name of 2nd Employee: ");
                name = scan.next();
                e2 = new Employee(name);
                System.out.println("Employee count is "+getCount());
    
                System.out.print("Enter name of 3rd Employee: ");
                name = scan.next();
                e3 = new Employee(name);
                System.out.println("Employee count is "+getCount());
    
                
                System.out.print("Enter name of 4th Employee: ");
                name = scan.next();
                e4 = new Employee(name);
                System.out.println("Employee count is "+getCount());
    
                
                e1.setEmployeePay(22.50,35.0);
                e2.setEmployeePay(45350.00);
                e3.setEmployeePay(500.00, 25);
                e4.setEmployeePay(14.75,48.0);
                
                double earnings;
                DecimalFormat df = new DecimalFormat("#.##");
                
                earnings = e1.calculatePay();
                System.out.println("Employee "+e1.getNumber()+ " "+e1.getName()+" earned: $"+df.format(earnings));
                
                earnings = e2.calculatePay();
                System.out.println("Employee "+e2.getNumber()+ " "+e2.getName()+" earned: $"+df.format(earnings));
                
                earnings = e3.calculatePay();
                System.out.println("Employee "+e3.getNumber()+ " "+e3.getName()+" earned: $"+df.format(earnings));
                
                earnings = e4.calculatePay();
                System.out.println("Employee "+e4.getNumber()+ " "+e4.getName()+" earned: $"+df.format(earnings));
            }
    
        }
    }
    I also have an Employee class file but that has no errors.

    So there are a few errors in the lab01 one. One is that in line 15 it says cannot find symbol; symbol class: Employee; location class: Lab01. And in line 22 for example it says cannot find symbol; symbol: method getCount(); location class: Lab01. As you can see both Employee and getCount() repeat in the program but I thought I would just give one example.

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: A couple errors in program

    You don't have a getCount() method defined anywhere, so it's little wonder that the compiler grumbles...

    Perhaps the question gives you some clue where this method should reside. As a static method of Employee (yuk! but the sad truth is that many assignments of this type have a large yuk factor) or maybe you are supposed to create an instance of Lab01 and have getCount() be a method of that. Anyway, *somewhere* you need a getCount() method, documented to do something in particular.

    For the other error the compiler can't find the Employee class. (it is looking for it in the lab01 package.) Check (1) that you have a Employee.java file (!) (2) that the file is in the lab01 folder and (3) that Eployee.java starts with the correct package statement.

    That should keep Java's accounting machinery happy. If you still get the errors post the source files, their location on disk and the command ypu are using to compile.

  3. #3
    gusten is offline Member
    Join Date
    Jul 2013
    Posts
    19
    Rep Power
    0

    Default Re: A couple errors in program

    Any idea what this means? It appeared in my output when I tried to re-run the program...

    java.lang.NoClassDefFoundError: lab01/Lab01 (wrong name: Lab01/Lab01)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java :791)
    at java.security.SecureClassLoader.defineClass(Secure ClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader .java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader. java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:4 23)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 56)
    at sun.launcher.LauncherHelper.checkAndLoadMain(Launc herHelper.java:482)
    Exception in thread "main" Java Result: 1

  4. #4
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    757
    Rep Power
    7

    Default Re: A couple errors in program

    How do you run your program? what command have you type to execute it? Looks like there was a type in the command.

  5. #5
    gusten is offline Member
    Join Date
    Jul 2013
    Posts
    19
    Rep Power
    0

    Default Re: A couple errors in program

    I'm using NetBeans and just hitting the run button.

  6. #6
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: A couple errors in program

    It might be significant that the runtime exception talks about a class being referred to using the "wrong name". Check point (2) of my previous post, including the capitalisation of the directory name.

  7. #7
    gusten is offline Member
    Join Date
    Jul 2013
    Posts
    19
    Rep Power
    0

    Default Re: A couple errors in program

    When I change the folder name, that the files are under, it says package already exists. Was that what you wanted me to do?

  8. #8
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,094
    Rep Power
    4

    Default Re: A couple errors in program

    What you should do is learn all about the classpath and packages so you can answer these questions for yourself. Just trying stuff and hoping for the best won't work. You'll save yourself a world of grief if you make the effort.

  9. #9
    gusten is offline Member
    Join Date
    Jul 2013
    Posts
    19
    Rep Power
    0

    Default Re: A couple errors in program

    I agree, just not sure where to start.

  10. #10
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,094
    Rep Power
    4

    Default Re: A couple errors in program

    A good book.

  11. #11
    gusten is offline Member
    Join Date
    Jul 2013
    Posts
    19
    Rep Power
    0

    Default Re: A couple errors in program

    I have a book for this course but it's hardly any help.

  12. #12
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    757
    Rep Power
    7

    Default Re: A couple errors in program

    What if you post the whole project directory in a zip file. Maybe I could test it here to see what the problem you have there.

  13. #13
    gusten is offline Member
    Join Date
    Jul 2013
    Posts
    19
    Rep Power
    0

    Default Re: A couple errors in program

    Would I be able to message you or email you the project instead? I don't want to have a full project laying around here, you know what I mean?

Similar Threads

  1. Getting a couple of errors on Payroll application
    By gabrielpr12 in forum New To Java
    Replies: 1
    Last Post: 01-27-2012, 08:40 PM
  2. How do I fix this program (2 errors)?
    By Logik22 in forum New To Java
    Replies: 17
    Last Post: 07-17-2011, 09:04 PM
  3. Help with some errors in my program
    By kbud123 in forum Java Applets
    Replies: 5
    Last Post: 05-11-2011, 05:08 AM
  4. Replies: 4
    Last Post: 01-04-2011, 12:36 AM
  5. Errors in Program (Right Triangle)
    By SupaStudy in forum New To Java
    Replies: 3
    Last Post: 03-26-2009, 10:42 AM

Posting Permissions

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