Java – error: unable to find or load the main class < < why do I receive this error?
•
Java
I don't seem to be able to make this code work properly This is the mistake I keep getting:
What caused this?
Payroll3. java
// A program to calculate and print the department,name,and pay of an employee. import java.util.Scanner; //program uses the Scanner class import java.io.*; class main { public class Payroll3 { // main method begins execution of Java program. public void main(String args[]) { // create Scanner to obtain input from the command window Scanner input = new Scanner (system.in); double number1; // first number to multiply double number2; // second number to multiply double product; // product of number1 and number2 while(true){ // infinite loop System.out.print("Enter Department name: "); //prompt String name = input.nextLine(); // read name from user if(name.equals("stop")) // exit the loop break; System.out.print("Enter number of employees: "); // prompt number1 = input.nextDouble(); // read first number from user input.nextLine(); while( number1 <= -1){ System.out.print("Enter positive number of employees:"); // prompt number1 = input.nextDouble(); // read first number from user input.nextLine(); } /* while statement with the condition that negative numbers are entered user is prompted to enter a positive number */ System.out.print("Enter average salary: "); // prompt number2 = input.nextDouble(); // read second number from user input.nextLine(); while( number2 <= -1){ System.out.print("Enter positive number for average salary:"); // prompt number2 = input.nextDouble(); // read first number from user input.nextLine(); } /* while statement with the condition that negative numbers are entered user is prompted to enter a positive number */ // make department object Department dept = new Department(name,number1,number2); product = number1 * number2; // multiply numbers System.out.println("Department name:" + name); // display Department name System.out.printf("Payroll is: $%.2f\n",product); // display product } // end while method } // end method main }/* end class Payroll3 */ } // Stores data about an department class Department { //fields String name; double number1; double number2; // constructor public Department(String name,double number1,double number2) { this.name = name; this.number1 = number1; this.number2 = number2; } // returns the pay: public double getPay() { return number1*number2; } // getters and setters public String getName() { return name; } public void setName(String name) { this.name = name; } public double getnumber1() { return number1; } public void setNumber1(double number1) { this.number1 = number1; } public double getNumber2() { return number2; } public void setNumber2(double number2) { this.number2 = number2; } }
Solution
Class must be public and main must be static
public static void main(String argv[])
And you can't have nested main classes At least it may not be what you expect Why not start with a simple tutorial and extend it with your code?
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码