Step 1:First, you need to create an Employee class and declare class as follows
ID: 3682912 • Letter: S
Question
Step 1:First, you need to create an Employee class and declare class as follows
class Employee {
// declare some variables of different types:
// a String called empName
//-->
// an int called empID
//-->
// a String called empJob
//-->
// a double called empSalary
//-->
// an int called empRating
//-->
Step 3:Defining the constructor
public Employee (String employeeName, int employeeID, int employeeRating)
{
// write the segment of code
// that assigns input data to the data members }
Step 4: Adding the methods
You will need to create the following getter and setter methods: int getempID() String getName() double getempSalary() void setempSalary(double salary) void setempJob(String jobTitle)
In addition to the getter and setter methods, you will create an additional method that raises the salary of the employee based on the performance of the employee. Here is the logic to implement the raiseSalary() class:
If the number indicating the performance of the employee is 1, employee will receive a raise of 4%.
If the number indicating the performance of the employee is 2, employee will receive a raise of 2%.
If the number indicating the performance of the employee is 3, employee will not receive a raise.
void raiseSalary() { //finish implementing the raiseSalary method
if (empRating==1){ empSalary= empSalary+ (empSalary*0.04)
}
-->
}
Step 5: Calling the constructor and using the methods of the Employee class from the “main” method
The final task of this lab is use Employee class variables and methods. In order to do so, we need to have a runner function. Remember, for any class in java, “main” method will be the running method.
public class Lab9 { public static void main(String[] args) {
// Create a new Scanner object to take in input from the user.
// ->
// Prompt the user for the employee’s name
// ->
// Prompt the user for the employee’s ID
// ->
// Prompt the user for employee’s rating.
// ->
// create a new Employee object using the name,
// id, job, salary, and rating given by the user
//-->
//Since we did not prompt for job title
// use the setempJob(String jobTitle) to set the job to //Software Engineer
// -->
//Since we did not prompt for employee’s salary
// use the setempSalary(double salary) to set the salary to
//4000.00
// ->
// Print out the Employee’s information in the
// following format:
// Employee’s Information:
// ->
// The employee’s full name is:
// ->
// The employee’s ID number is:
// ->
// The employee’s current salary is:
// ->
// Attempt to check if employee’s is eligible for a salary raise
// Apply the raiseSalary() method to the employee’s object
// -->
// Print out the following:
// <Employee’s ID> new salary is <Employee Salary>
}
}
Sample Output
Enter employee's name: Jack Mann
Enter employee's Id: 123456789
Enter employee's rating: 1
Employee's Information
The employee’s full name is: Jack Mann
The employee’s ID number is: 123456789
The employee’s current salary is: 4000.0
Jack Mann new salary is y is: 4160.0
Enter employee's name: Bill John
Enter employee's Id: 98762345
Enter employee's rating: 3
Employee's Information The employee’s full name is: Bill John
The employee’s ID number is: 98762345
The employee’s current salary is: 4000.0
Bill John new salary is y is: 4000.0
Explanation / Answer
import java.util.*;
public class HelloWorld{
public static void main(String []args){
Scanner read=new Scanner(System.in);
System.out.print("Enter employee Name: ");
String empName=read.next();
System.out.print("Enter employee ID: ");
int empID=read.nextInt();
System.out.print("Enter employee rating: ");
int empRating=read.nextInt();
Employee e=new Employee(empName,empID,empRating);
e.setempJob("Software Engineer");
e.setempSalary(4000);
System.out.println("Employee's Information");
System.out.println("Employee's Full Name is: "+e.getName());
System.out.println("Employee's ID is: "+e.getempID());
System.out.println("Employee's current salary is: "+e.getempSalary());
e.raiseSalary();
System.out.println(e.getName() +"'s new salary is: "+e.getempSalary());
}
}
class Employee
{
String empName;
int empID;
String empJob;
Double empSalary;
int empRating;
public Employee (String employeeName, int employeeID, int employeeRating)
{
empName=employeeName;
empID=employeeID;
empRating=employeeRating;
}
int getempID()
{
return empID;
}
String getName()
{
return empName;
}
double getempSalary()
{
return empSalary;
}
void setempSalary(double salary)
{
empSalary=salary;
}
void setempJob(String jobTitle)
{
empJob=jobTitle;
}
void raiseSalary()
{
if (empRating==1)
empSalary= empSalary+ (empSalary*0.04);
else
if (empRating==2)
empSalary= empSalary+ (empSalary*0.02);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.