Java 错误:表达式void inputInfo()的启动非法;
我知道像这样的问题以前已经被回答过,但我似乎找不到任何分号缺失。那么,我的代码员怎么了?请帮忙 我的任务是:开发一个Java应用程序来计算不同类型员工的月工资。employee类型是基于父基类employee在子类数组中创建的。为每个类和驱动程序类提供初始代码。下面是我为主课准备的内容。当我将inputInfo方法置于main之外,然后尝试使用它时,会收到大量错误消息,例如:Java 错误:表达式void inputInfo()的启动非法;,java,Java,我知道像这样的问题以前已经被回答过,但我似乎找不到任何分号缺失。那么,我的代码员怎么了?请帮忙 我的任务是:开发一个Java应用程序来计算不同类型员工的月工资。employee类型是基于父基类employee在子类数组中创建的。为每个类和驱动程序类提供初始代码。下面是我为主课准备的内容。当我将inputInfo方法置于main之外,然后尝试使用它时,会收到大量错误消息,例如: 错误:找不到符号 收益=输入。nextDouble(); ^ 符号:可变收益 位置:类别PayrollSystemTes
错误:找不到符号
收益=输入。nextDouble();
^
符号:可变收益
位置:类别PayrollSystemTest
PayrollSystemTest.java:68:错误:找不到符号
收益=输入。nextDouble();
^
符号:变量输入
位置:类别PayrollSystemTest
PayrollSystemTest.java:69:错误:找不到符号
dob=新日期(月、日、年);
^
符号:可变dob
位置:类别PayrollSystemTest
PayrollSystemTest.java:69:错误:找不到符号
dob=新日期(月、日、年);
^
符号:可变月份
位置:类别PayrollSystemTest
PayrollSystemTest.java:69:错误:找不到符号
dob=新日期(月、日、年);
^
符号:可变日
位置:类别PayrollSystemTest
PayrollSystemTest.java:69:错误:找不到符号
dob=新日期(月、日、年);
^
符号:可变年份
位置:类别PayrollSystemTest
PayrollSystemTest.java:70:错误:找不到符号
SalariedEmployee salariedEmployee1=新的SalariedEmployee(名字、姓氏、socialNum、dob、收入);
^
符号:变量名
位置:类别PayrollSystemTest
PayrollSystemTest.java:70:错误:找不到符号
SalariedEmployee salariedEmployee1=新的SalariedEmployee(名字、姓氏、socialNum、dob、收入);
^
符号:变量lastName
位置:类别PayrollSystemTest
PayrollSystemTest.java:70:错误:找不到符号
SalariedEmployee salariedEmployee1=新的SalariedEmployee(名字、姓氏、socialNum、dob、收入);
^
符号:变量socialNum
位置:类别PayrollSystemTest
PayrollSystemTest.java:70:错误:找不到符号
SalariedEmployee salariedEmployee1=新的SalariedEmployee(名字、姓氏、socialNum、dob、收入);
^
符号:可变dob
位置:类别PayrollSystemTest
PayrollSystemTest.java:70:错误:找不到符号
SalariedEmployee salariedEmployee1=新的SalariedEmployee(名字、姓氏、socialNum、dob、收入);
^
符号:可变收益
位置:类别PayrollSystemTest
PayrollSystemTest.java:75:错误:找不到符号
收益=输入。nextDouble();
^
符号:可变收益
位置:类别PayrollSystemTest
PayrollSystemTest.java:75:错误:找不到符号
收益=输入。nextDouble();
^
符号:变量输入
位置:类别PayrollSystemTest
PayrollSystemTest.java:76:错误:找不到符号
dob=新日期(月、日、年);
^
符号:可变dob
位置:类别PayrollSystemTest
PayrollSystemTest.java:76:错误:找不到符号
dob=新日期(月、日、年);
^
符号:可变月份
位置:类别PayrollSystemTest
PayrollSystemTest.java:76:错误:找不到符号
dob=新日期(月、日、年);
^
符号:可变日
位置:类别PayrollSystemTest
PayrollSystemTest.java:76:错误:找不到符号
dob=新日期(月、日、年);
^
符号:可变年份
位置:类别PayrollSystemTest
PayrollSystemTest.java:77:错误:找不到符号
SalariedEmployee salariedEmployee2=新的SalariedEmployee(名字、姓氏、socialNum、dob、收入);
^
符号:变量名
位置:类别PayrollSystemTest
PayrollSystemTest.java:77:错误:找不到符号
SalariedEmployee salariedEmployee2=新的SalariedEmployee(名字、姓氏、socialNum、dob、收入);
^
符号:变量lastName
位置:类别PayrollSystemTest
PayrollSystemTest.java:77:错误:找不到符号
SalariedEmployee salariedEmployee2=新的SalariedEmployee(名字、姓氏、socialNum、dob、收入);
^
符号:变量socialNum
位置:类别PayrollSystemTest
PayrollSystemTest.java:77:错误:找不到符号
SalariedEmployee salariedEmployee2=新的SalariedEmployee(名字、姓氏、socialNum、dob、收入);
^
符号:可变dob
位置:类别PayrollSystemTest
PayrollSystemTest.java:77:错误:找不到符号
SalariedEmployee salariedEmployee2=新的SalariedEmployee(名字、姓氏、socialNum、dob、收入);
^
符号:可变收益
位置:类别PayrollSystemTest
PayrollSystemTest.java:82:错误:找不到符号
grossales=input.nextDouble();
^
import java.util.Scanner;
public class PayrollSystemTest
{
public static void main( String args[] )
{
Employee employees[] = new Employee[ 5 ];
int i = 0;
inputInfo();
System.out.print("What are the earnings of the salaried
employee?");
earnings = input.nextDouble();
dob = new Date(month, day, year);
SalariedEmployee salariedEmployee1 = new
SalariedEmployee(firstName, lastName, socialNum, dob,
earnings);
employees[i] = salariedEmployee1; i++;
inputInfo();
System.out.print("What are the earnings of the next salaried
employee?");
earnings = input.nextDouble();
dob = new Date(month, day, year);
SalariedEmployee salariedEmployee2 = new
SalariedEmployee(firstName, lastName, socialNum, dob,
earnings);
employees[i] = salariedEmployee2; i++;
inputInfo();
System.out.print("What are the gross sales of the commission
employee?");
grossSales = input.nextDouble();
System.out.print("What is the commission rate?");
commissionRate = input.nextDouble();
dob = new Date(month, day, year);
CommissionEmployee commissionEmployee = new
CommissonEmployee(firstName, lastName, socialNum, dob,
grossSales, commissonRate);
employees[i] = commissionEmployee; i++;
inputInfo();
System.out.print("What are the gross sales of the base plus
commission employee?");
grossSales = input.nextDouble();
System.out.print("What is the commission rate?");
commissionRate = input.nextDouble();
System.out.print("What is the base salary of the base plus
commission employee?");
baseSalary = input.nextDouble();
dob = new Date(month, day, year);
BasePlusCommissionEmployee basePlusCommissionEmployee = new
BasePlusCommissionEmployee(firstName, lastName,
socialNum,
dob, grossSales, commissionRate, baseSalary);
employees[i] = basePlusCommissionEmployee; i++;
inputInfo();
System.out.print("What is the wage of the hourly
employee?");
wage = input.nextDouble();
System.out.print("What are the hours of the hourly
employee?");
hours = input.nextDouble();
dob = new Date(month, day, year);
HourlyEmployee hourlyEmployee = new
HourlyEmployee(firstName,
lastName, socialNum, dob, wage, hours);
employees[i] = hourlyEmployee; i++;
System.out.println( "Employees processed polymorphically:\n"
);
// generically process each element in array employees
for ( Employee currentEmployee : employees )
{
System.out.println( currentEmployee ); // invokes
toString
if(currentEmployee instanceof SalariedEmployee)
{
SalariedEmployee employee = (SalariedEmployee)
currentEmployee;
double oldBaseSalary = employee.getWeeklySalary();
employee.setWeeklySalary(4 * oldBaseSalary);
System.out.printf("earned: ", employee.earnings());
}
if(currentEmployee instanceof HourlyEmployee)
{
HourlyEmployee employee = (HourlyEmployee) currentEmployee;
double oldBaseSalary = employee.getHours() *
employee.getWage();
employee.setWage(4 * oldBaseSalary);
System.out.printf("earned: ", employee.getWage());
}
if(currentEmployee instanceof CommissionEmployee)
{
CommissionEmployee employee = (CommissonEmployee)
currentEmployee;
double oldBaseSalary = employee.getGrossSales() *
employee.getCommissionRate();
employee.setGrossSales(4 * oldBaseSalary);
System.out.printf("earned: ", employee.getGrossSales());
}
// determine whether element is a BasePlusCommissionEmployee
if ( currentEmployee instanceof BasePlusCommissionEmployee )
{
// downcast Employee reference to
// BasePlusCommissionEmployee reference
BasePlusCommissionEmployee employee =
( BasePlusCommissionEmployee ) currentEmployee;
double oldBaseSalary = employee.getBaseSalary();
employee.setBaseSalary( 4 * oldBaseSalary );
System.out.printf(
"new base salary with 10%% increase is: $%,.2f\n",
employee.getBaseSalary() );
} // end if
System.out.printf(
"earned $%,.2f\n\n", currentEmployee.earnings() );
} // end for
// get type name of each object in employees array
for ( int j = 0; j < employees.length; j++ )
System.out.printf( "Employee %d is a %s\n", j,
employees[ j ].getClass().getName() );
} // end main
static void inputInfo()
{
Scanner input = new Scanner(System.in);
String firstName;
String lastName;
String socialNum;
double earnings;
int month;
int day;
int year;
double wage;
double hours;
double grossSales;
double commissionRate;
double baseSalary;
Date dob = new Date();
System.out.print("What is the first name of the employee?");
firstName = input.next();
System.out.print("What is the last name of the employee?");
lastName = input.next();
System.out.print("What is the social security number of the
employee?");
socialNum = input.next();
System.out.print("What month was the employee born?");
month = input.nextInt();
System.out.print("What day was the employee born?");
day = input.nextInt();
System.out.print("What year was the employee born?");
year = input.nextInt();
}
} // end class PayrollSystemTest
package test.file;
import java.util.Date;
import java.util.Scanner;
public class PayrollSystemTest {
public static void main(final String args[]) {
inputInfo();
}
static void inputInfo() {
double baseSalary;
double commissionRate;
int day;
Date dob = new Date();
double earnings;
String firstName;
double grossSales;
double hours;
Scanner input = new Scanner(System.in);
String lastName;
int month;
String socialNum;
double wage;
int year;
System.out.print("What is the first name of the employee?");
firstName = input.next();
System.out.print("What is the last name of the employee?");
lastName = input.next();
System.out.print("What is the social security number of the employee?");
socialNum = input.next();
System.out.print("What month was the employee born?");
month = input.nextInt();
System.out.print("What day was the employee born?");
day = input.nextInt();
System.out.print("What year was the employee born?");
year = input.nextInt();
}
}