I got what seems to be a simple exercise with a simple answer.. However, I can't get this code to run properly!! I'm just starting a course at my local community college and am using Java How to Program Edition 9 and am stuck.. Here is the exercise.. Sorry for the huge first post but I have been at this for hours and have hit a wall...
Here is what I have in my code...3.14 (Employee Class) Create a class called Employee that includes three instance variables-a first name (type String), a last name (type String) and a monthly salary (double). Provide a constructor that initializes the three instance variables. Provide a set and a get method for each instance variable. If the monthly salary is not positive, do not set its value. Write a test application named EmployeeTest that demonstrates class Employee's capabilities. Create two Employee objects and display each object's yearly salary. Then give each Employee a 10% raise and display each Employee's yearly salary again.
Employee.java
Now here is my EmployeeTest.java//This class is called Employee and works with name and salary //James public class Employee { private String firstName; private String lastName; private double monthlySalary; public Employee() { firstName = null; lastName = null; monthlySalary = 0.0; } public String getfirstName() { return firstName; } public String getlastName() { return lastName; } public double getSalary() { return monthlySalary; } public void setfirstName(String first) { firstName = first; } public void setlastName(String last) { lastName = last; } public void setSalary(double salary) { monthlySalary = salary; } }
//This is a test file. //James import java.util.Scanner; public class EmployeeTest { public static void main( String args[] ) { Employee employee1 = new Employee(); Employee employee2 = new Employee(); Scanner input = new Scanner( System.in ); String first; String last; double salary; System.out.print( "Enter the first name of the first employee: " ); first = input.next(); employee1.setfirstName( first ); System.out.print( "Enter the last name of the first employee: " ); last = input.next(); employee1.setlastName( last ); System.out.print( "Enter the first employee's monthly salary: " ); salary = input.nextDouble(); employee1.setSalary( salary ); System.out.print( "Enter the first name of the second employee: " ); first = input.next(); employee2.setfirstName( first ); System.out.print( "Enter the last name of the second employee: " ); last = input.next(); employee2.setlastName( last ); System.out.print( "Enter the second employee's monthly salary: " ); salary = input.nextDouble(); employee2.setSalary( salary ); System.out.printf( "Now displaying employees' full names and annual salary.\n"); System.out.printf( employee1.getfirstName()," ", employee1.getlastName(), " ", employee1.getSalary() * 12, "\n" ); System.out.printf( employee2.getfirstName()," ", employee2.getlastName(), " ", employee2.getSalary() * 12, "\n" ); System.out.printf( "Now applying a 10% raise to each employee and displaying the updated information.\n"); System.out.printf( employee1.getfirstName()," ", employee1.getlastName(), " ", employee1.getSalary() * 12, "\n" ); System.out.printf( employee2.getfirstName()," ", employee2.getlastName(), " ", employee2.getSalary() * 12, "\n" ); } }
Now when I try to run I get this specific error: Exception in thread "main" java.lang.Error: Unresolved compilation problems: Employee cannot be resolved to a type
What have I done wrong here??