Hello. I'm having some issues with my code. When I try to execute it, it gives this exception:
Exception in thread "main" java.lang.NoClassDefFoundError: Employee
Caused by: java.lang.ClassNotFoundException: Employee
at java.net.URLClassLoader$1.run(URLClassLoader.java: 202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.j ava:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:3 06)
at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:2 47)
Because there is no line number, I cannot determine which line of code is giving the error. Is it because of something wrong in my code or my java environment? If so, how would I fix it. Thanks, my code is pasted below.
import java.util.Scanner; public class Employee { //Varibales private static double salary, rate, hours, weeklyPay = 0; private static String name; private static String type; static boolean bonusPay = false; //Constructor creates Employee object public Employee(String name, String status, double hours, double rate, double salary, boolean bonusPay) { if (status == "salaried") { this.salary = salary; if(bonusPay == true) { salary = salary * 1.1; } } else { this.rate = rate; this.hours = hours; if(hours > 40) { //calculates and adds overtime pay weeklyPay = (hours - 40) * (2*(salary)) + 40 * salary; } else { weeklyPay = rate * hours; } } } //Methods to obtain information about a specific employee private double getWeeklyPay() { return weeklyPay; }private String getName() { return name; }private double getSalary() { return salary; }private String getType() { return type; }private double getHours() { return hours; }private double getRate() { return rate; } private void printData(Employee x) { } public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Hello! Welcome to Employee Database"); System.out.println("If Employee is salaried enter S. Otherwise enter H for hourly"); if(input.next().toLowerCase().contains("s")) { type = "salaried"; } else { type = "hourly"; } System.out.println("Enter Employee's full name"); name = input.next(); if(type == "salary") { System.out.println("Enter weekly salary"); salary = input.nextDouble(); System.out.println("Enter Y if employee receives a bonus of 10%, otherwise enter N"); if(input.next().toLowerCase().contains("y")) { bonusPay = true; } else { bonusPay = false; } } else { System.out.println("Enter hourly pay"); rate = input.nextDouble(); System.out.println("Enter # of hours"); hours = input.nextDouble(); } Employee Employee1 = new Employee(name, type, rate, hours, salary, bonusPay); System.out.println(); System.out.println("\t Name Status Hours Rate Weekly Pay Amount"); System.out.println("\t======================================================================"); System.out.println(Employee1.getName() + Employee1.getType() + Employee1.getHours() + Employee1.getRate() + Employee1.getWeeklyPay()); System.out.println(); } }