我正在使用Dr.Java,当我运行程序时我得到了错误,但是在另一个非常类似的程序上,错误消失并且正常符文。
欢迎来到DrJava。工作目录是E:\ Inheritance 运行员工 静态错误:此类没有接受String []的静态void main方法。 “欢迎来到DrJava。工作目录是E:\ Inheritance 运行员工 静态错误:此类没有接受String []的静态void main方法。
import java.util.*;
public class Employee{
//class variables
protected String name = "";
protected int idNumber;
protected double salary;
protected String department = "";
//default values
protected final String default_name = "Bob";
protected final int default_idNumber = 1234;
protected final double default_salary = 50000;
protected final String default_department = "Janitor";
//Constructors
public Employee( String ename, int eidNumber, double esalary, String
edepartment){
name = ename;
idNumber = eidNumber;
salary = esalary;
department = edepartment;
}
//default
public Employee(){
name = default_name;
idNumber = default_idNumber;
salary = default_salary;
department = default_department;
}
//Methods
public void printRecords(){
System.out.println("\n----------------------");
System.out.println("Name: " + name);
System.out.println("idNumber: " + idNumber);
System.out.println("salary " + salary);
System.out.println("department: " + department);
System.out.println("----------------------\n");
}
public void changeSalary(){
Scanner input = new Scanner(System.in);
System.out.println("Change Salary, (0 - 1)");
double psc = input.nextDouble();
salary = salary + (salary * psc);
}
public double getSalary(){
return salary;
}
public void menu(){
Scanner input = new Scanner(System.in);
printRecords();
int choice = 1;
while (choice != 0)
{
System.out.println("Selection: ");
System.out.println("0. Exit");
System.out.println("1. Print Records");
System.out.println("2. Change Salary");
System.out.println("3. Access salary");
choice = input.nextInt();
switch (choice)
{
case 1:
{
printRecords();
break;
}
case 2:
{
changeSalary();
break;
}
case 3:
{
getSalary();
break;
}
}
}
System.out.println("Complete");
}
//Main method to instanciate and run the object
public static void main(String[] args){
Employee emp = new Employee();
emp.menu();
}
}
答案 0 :(得分:0)
我把你的代码放在drjava-beta-20160913-225446(实际上是默认设置),编译并运行它,它运行正常(没有错误)。检查DrJava设置或获取不同版本的DrJava。