Reputation: 2276
This feels extremely like a duplicate of another problem, but I haven't been able to find a solution. In both Eclipse(Java) and JGrasp, no matter what I do, the IDE refuses to compile the class libraries I have with it.
I have already attempted to add the libraries manually in Eclipse with the build path configuration, creating a folder in the workspace, copying the class files into it, then adding that folder to the Classpath.
In JGrasp, I have read that simply having the class file in the same directory as the runner file is sufficient.
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 error:
----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)\jGRASP\extensions\classes".
----jGRASP wedge2: working directory is [H:\APCS\2019-2020 AP Computer Science\Unit 2\payrolltest] platform id is 2.
----jGRASP wedge2: actual command sent ["C:\Program Files\jdk-10.0.2\bin\javac.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.
Class file is already compiled.
Upvotes: 1
Views: 551
Reputation: 86
In jGRASP, turn on "Settings" > "Verbose Messages", then the output of compilation will also show the classpath. There may be something weird about your classpath.
Make sure Employee.class is named correctly (proper case, no hidden additional extension).
If Employee is in a package, you need to replicate that package structure as a directory structure, so if it is in package "company", you need a directory named "company" in the directory containing "Main" (or elsewhere on the classpath), and Employee.class would be in that directory.
If you do have a .jar version of this library, you can use "Settings" > "PATH / CLASSPATH" > "Workspace" (or "Project ..." if you are using projects) to add it to the classpath in jGRASP.
Upvotes: 1