This file is saved as Employee.java
// Employee.java
//Employee Class with a construuctor to initialize the first name, last .
public class Employee
{
private String FirstName; //first name for this Employee
private String LastName ; //last name for this Employee
private double MonthlySalary; //Monthly salary for this Employee
//constructor initializes FirstName and LastName with String argument and initializes MonthlySalary with double argument
public Employee(String FN, String LN, double MS)
{
String FirstName = FN; // initializes FirstName
String LastName = LN; //initializes LastName
double MonthlySalary = MS; //initializes MonthySalary
// MonthlySalary (MS);
}//end constructor
//method to set the FirstName
public void setFirstName(String FN)
{
FirstName = FN; //store the course name
}
//method to set the LastName
public void setLastName(String LN)
{
LastName = LN;
}
//method to set the MonthlySalary
public void setMonthlySalary(double MS)
{
//if statement to make sure that monthly salary is not negative
if(MonthlySalary >= 0)
MonthlySalary = MS;
else
MonthlySalary = 0;
}
//method to retrieve the FirstName
public String getFirstName()
{
return FirstName;
}//end method getFirstName
//method to retrieve the LastName
public String getLastName()
{
return LastName;
}
//method to retrieve the MonthlySalary
public double getMonthlySalary()
{
return MonthlySalary;
}
//display a welcome message to the Employee user
public void displayEmployees()
{
//this statement calls getFirstName, getLastName, getMonthlySalary
System.out.printf( "%s %s makes %d monthly \n",
getFirstName(), getLastName(), getMonthlySalary());
}//end method displayMessage
}//end class Employee
This one is saved as EmployeeTest.java
//EmployeeTest.java
//Employee consturctor used to specify the first and last name of two employees and their monthly and yearly pay.
public class EmployeeTest
{
//main method begins program execution
public static void main( String[] args )
{
//create GradeBook object
Employee worker1 = new Employee(
" Josh", " King ", "3,265" );
Employee worker2 = new Employee(
" Sasuke", " Uchiha", "10,000");
//display initial value of courseName for each GradeBook
System.out.printf( " %s %s makes %d monthly \n" ,
worker1.getFirstName(), worker1.getLastName(), worker1.getMonthlySalary());
System.out.printf( " %s %s makes %d monthly \n" ,
worker2.getFirstName(), worker2.getLastName(), worker2.getMonthlySalary());
}//end main
}//end class EmployeeTest
Errors:
2 errors found:
File: J:\Documents\Java Programming\HW2\Extra Credit\EmployeeTest.java [line: 11]
Error: J:\Documents\Java Programming\HW2\Extra Credit\EmployeeTest.java:11: cannot find symbol
symbol : constructor Employee(java.lang.String,java.lang.String,java.lang.String)
location: class Employee
File: J:\Documents\Java Programming\HW2\Extra Credit\EmployeeTest.java [line: 14]
Error: J:\Documents\Java Programming\HW2\Extra Credit\EmployeeTest.java:14: cannot find symbol
symbol : constructor Employee(java.lang.String,java.lang.String,java.lang.String)
location: class Employee