Question: Create a class called Employee that include three instance variables a first name(String), a last name (String), and a monthly salary (double). Provide a constructor
Create a class called Employee that include three instance variables a first name(String), a last name (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. Set the monthly salary value, if it is positive. Write a test application named EmployeeTest that demonstrates class Employeess capabilities. Create at-least five Employee objects and display each objects yearly salary. Give each employee a range of raises (2%-6%) and then display their yearly salary again. Write good interactive messages for users while they are interacting with the program (introductory message and a good bye message).
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
I cant figure out the following 3 parts to this java code :
1 need to add five employees only do one right now
2 on the test part when I enter each employee first name last name and monthly salary, need to add a raise of 2-6% to each employee
3 get the display message to show at end
heres what I have so far
public class Employee {
private String firstName;
private String lastName;
private double monthlySalary;
public Employee (double monthly )
{
if ( monthly > 0.00 )
monthlySalary = monthly;
if ( monthly< 0.00 )
monthlySalary = 0.00;
} // end Salary constructor
// method to set first name
public void setFirstName( String first )
{
firstName = first;
} // end method setFirstName
// method to set last name
public void setLastName( String last )
{
lastName = last;
} // end method setLastName
// method to set monthlysalary
public void setMonthlySalary( double monthly )
{
monthlySalary = monthly;
} // end method set LastName
// method to retrieve firstname
public String getFirstName()
{
return firstName;
} // end method getFirstName
// method to retrieve lastname
public String getLastName()
{
return lastName;
} // end method getFirstName
// method to retrieve firstname
public double getMonthlySalary()
{
return monthlySalary;
} // end method getMonthlySalary
// method to display employee information to user
public void displayMessage()
{
System.out.println(getFirstName()+" "+ getLastName()+" has a monthly salary of "+ getMonthlySalary());
} // end method displayMessage
} // end class Employee
-------------------------------------------------------------------------------------------------------------------------------------------
import java.util.Scanner;// program uses class Scanner
public class EmployeeTest {
// main method begins execution of Java application public static void main( String args[] ) { Scanner input = new Scanner(System.in );
Employee newEmployee = new Employee( 0.00 );
System.out.println( "Please enter Employee's firstname:" ); String first = input.nextLine(); newEmployee.setFirstName( first ); System.out.println();
System.out.println( "Please enter Employee's lastname:" ); String last = input.nextLine(); newEmployee.setLastName( last ); System.out.println();
System.out.println( "Please enter Employee'smonthly salary:" ); double monthly = input.nextDouble(); newEmployee.setMonthlySalary( monthly ); System.out.println();
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
