This what I have so far but I and I can't get the test to work because of some problem with the constructor.
Expand|Select|Wrap|Line Numbers
- package employee;
- public class Employee {
- private String firstName;
- private String lastName;
- private double _monthlySalary; // monthly salary
- public int dependents;
- //constructor
- public Employee(String first, String last, double salary, int dep)
- {
- firstName= first;
- lastName= last;
- _monthlySalary= salary;
- dependents= dep;
- }
- // end Employee constructor
- public String getFirstName()
- {
- return firstName;
- }
- public void setFirstName(String first)
- {
- firstName= first;
- }
- public String getLastName()
- {
- return lastName;
- }
- public void setLastName(String last)
- {
- lastName= last;
- }
- public int getDependents()
- {
- return dependents;
- }
- public void setDependents (int dep)
- {
- dependents= dep;
- }
- public void setMonthlySalary ( double salary)
- {
- _monthlySalary= salary;
- }
- public double getMonthlySalary ()
- {
- return _monthlySalary;
- }
- public double getAnnualSalary()
- {
- return getMonthlySalary() *12;
- }
- }
here is the test
Expand|Select|Wrap|Line Numbers
- package employee;
- import java.util.Scanner;
- public class EmployeeTest
- {
- public static void main( String args[] )
- {
- Employee e1 = 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.setMonthlySalary( 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.setMonthlySalary( salary );
- System.out.printf( "Now displaying employees' full names and annual salary.\n");
- System.out.printf( employee1.getFirstName()," ", employee1.getLastName(), " ", employee1.getAnnualSalary(), "\n" );
- System.out.printf( employee2.getFirstName()," ", employee2.getLastName(), " ", employee2.getAnnualSalary(), "\n" );
- }
- }