这感觉非常像另一个问题的重复,但我无法找到解决方案。在Eclipse(Java(和JGrasp中,无论我做什么,IDE都拒绝编译我所拥有的类库。
我已经尝试使用构建路径配置在 Eclipse 中手动添加库,在工作区中创建一个文件夹,将类文件复制到其中,然后将该文件夹添加到类路径中。
在 JGrasp 中,我读到只需将类文件与 runner 文件放在同一目录中就足够了。
public class PayrollLoop
{
public static void main(String[] args)
{
// Prepare to receive output
Scanner scan = new Scanner(System.in);
// initialize variables
int numberEmployees = 0;
double totalGrossPay = 0;
double averagePay = 0;
Payroll employee = new Payroll();
String repeat = "yes";
// Loop to ask for repeated entry of employees.
// New String method: stringObject.equals(anotherStringObject).
// This method returns a boolean value of True or False.
while ( repeat.equals("yes") )
{
// prompt and scan for employee name
System.out.print("Enter the name: ");
employee.setName( scan.next() );
// prompt and scan for ID number
System.out.print("Enter the id number: ");
employee.setIdNumber( scan.nextInt() );
// prompt and scan for pay rate
System.out.print("Enter the pay rate: ");
employee.setPayRate( scan.nextDouble() );
// prompt and scan for hours worked
System.out.print("Enter the number of hours worked: ");
employee.setHoursWorked(scan.nextDouble());
// what should you do to the numberEmployees variable here?
numberEmployees ++;
// what should you do to the totalGrossPay variable here?
// use the getter methods to print all the employee values
System.out.println("Name " + employee.getName());
System.out.println("Id number " + employee.getIdNumber());
System.out.println("Pay Rate " + employee.getPayRate());
System.out.println("Hours Worked " + employee.getHoursWorked());
System.out.println("Gross Pay " + employee.grossPay());
System.out.println();
// Ask user if entering another and scan for response
System.out.println();
} // end of the while loop
// calculate average pay
averagePay = totalGrossPay / numberEmployees;
// print average pay
System.out.println("The average pay is: " + averagePay);
} // end of main method
}
jGASP 错误:
----jGRASP exec: javac -g PayrollLoop.java
---- at: Oct 8, 2019, 1:15:39 PM
----jGRASP wedge: pid for wedge is 2648.
----jGRASP wedge2: pid for wedge2 is 784.
----jGRASP wedge2: CLASSPATH is ";.;;;C:Program Files (x86)jGRASPextensionsclasses".
----jGRASP wedge2: working directory is [H:APCS2019-2020 AP Computer ScienceUnit 2payrolltest] platform id is 2.
----jGRASP wedge2: actual command sent ["C:Program Filesjdk-10.0.2binjavac.exe" -g PayrollLoop.java].
----jGRASP wedge2: pid for process is 5304.
PayrollLoop.java:35: error: ';' expected
System.out.println("Enter the pay rate: ")
^
1 error
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.
类文件已编译。
在 jGRASP 中,打开"设置">"详细消息",则编译的输出也会显示类路径。您的类路径可能有些奇怪。
确保 Employee.class 的名称正确(大小写正确,没有隐藏的附加扩展名(。
如果 Employee 在包中,则需要将该包结构复制为目录结构,因此如果它位于包"company"中,则需要在包含"Main"的目录中(或类路径上的其他位置(中名为"company"的目录,并且 Employee.class 将位于该目录中。
如果您确实有此库的.jar版本,则可以使用"设置">"路径/类路径">"工作区"(或"项目..."如果您使用的是项目(,以将其添加到 jGRASP 中的类路径中。