Question

In one file create an Employee class as per the following specifications: three private instance variables:...

In one file create an Employee class as per the following specifications:

  1. three private instance variables: name (String), startingSalary (int), yearlyIncrement (int)

  2. a single constructor with three arguments: the name, the starting salary, and the yearly increment. In the constructor, initialize the instance variables with the provided values.

  3. get and set methods for each of the instance variables.

  4. A computation method, computeCurrentSalary, that takes the number of years in service as its argument. The method returns the current salary using the calculation: startingSalary + years * yearlyIncrement

In a separate file, create a driver as follows:

  • In the main method, create two Employee objects: Alice with a starting salary of 50000 and a yearly increment of 1000 and Bob with a starting salary of 40000 and a yearly increment of 2500. Write a loop to display the current salaries of the two employees at the end of years 1 through 10. A sample output is shown below.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the code for the above assignment.

Feel free to comment on any doubt and give thumbs up!

There are 2 files that contain the code.

1. Employee.java which contains the Employee class with all the necessary members

2. Driver.java which contains the main method.

Code for Employee.java

class Employee

{

// Private data members

private String name;

private int startingSalary;

private int yearlyIncrement;

// constructor

public Employee(String name, int startingSalary, int yearlyIncrement)

{

this.name = name;

this.startingSalary = startingSalary;

this.yearlyIncrement = yearlyIncrement;

}

// setter method

public void setName(String name){

this.name = name;

}

public void setStartingSalary(int sal){

startingSalary = sal;

}

public void setYearlyIncrement(int inc){

this.yearlyIncrement = inc;

}

// getters

public String getName()

{

return name;

}

public int getStartingSalary(){

return startingSalary;

}

public int getYearlyIncement(){

return yearlyIncrement;

}

public int computeCurrentSalary(int years){

return startingSalary + (years * yearlyIncrement);

}

}

Code for Driver.java

public class Driver{

public static void main(String[] args) {

// creating objects

Employee alice = new Employee("Alice", 50000, 1000);

Employee bob = new Employee("Bob", 40000, 2500);

// loop to print salary.

for(int i = 0 ; i < 10 ; ++i){

System.out.println("Salary of Alice at the end of year " + (i+1) + " is " + alice.computeCurrentSalary(i+1));

System.out.println("Salary of Bob at the end of year " + (i+1) + " is " + bob.computeCurrentSalary(i+1));

}

}

}

Screenshot

'

Thank you!

Add a comment
Know the answer?
Add Answer to:
In one file create an Employee class as per the following specifications: three private instance variables:...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create a class called Employee that includes three instance variables—a first name, a last name, and...

    Create a class called Employee that includes three instance variables—a first name, a last name, and a monthly salary. Code the default (no-args, empty) constructor. Provide a set and a get method for each instance variable. If the monthly salary is not positive, do not set its value.

  • Create the Employee class: The Employee class has three attributes: private: string firstName; string lastName; string...

    Create the Employee class: The Employee class has three attributes: private: string firstName; string lastName; string SSN; The Employee class has ▪ a no-arg constructor (a no-arg contructor is a contructor with an empty parameter list): In this no-arg constructor, use “unknown” to initialize all private attributes. ▪ a constructor with parameters for each of the attributes ▪ getter and setter methods for each of the private attributes ▪ a method getFullName() that returns the last name, followed by a...

  • create java application with the following specifications: -create an employee class with the following attibutes: name...

    create java application with the following specifications: -create an employee class with the following attibutes: name and salary -add constuctor with arguments to initialize the attributes to valid values -write corresponding get and set methods for the attributes -add a method in Employee called verify() that returns true/false and validates that the salary falls in range1,000.00-99,999.99 Add a test application class to allow the user to enter employee information and display output: -using input(either scanner or jOption), allow user to...

  • You are to create a class Appointment.java that will have the following: 5 Instance variables: private...

    You are to create a class Appointment.java that will have the following: 5 Instance variables: private String month private int day private int year private int hour private int minute 1 default constructor public Appointment() 1 non-default constructor that accepts arguments for all instance variables, your constructor must call the setter methods below to set the values of the instance variables public Appointment(String monthPassed, int dayPassed, int yearPassed, int hourPassed, int minutePassed) 5 setter methods (one for each instance variable)...

  • E2a: Create a class called Employee that includes three pieces of information as data members---a first...

    E2a: Create a class called Employee that includes three pieces of information as data members---a first name (char array), last name (char array) and a monthly salary (integer). Your class should have a constructor that initializes the three data members. If the monthly salary is not positive, set it to 0. Write a test program that demonstrates class Employee’s capabilities. Create two Employee objects and display each object’s yearly salary. Then give each Employee a 10 percent raise and display...

  • In a project named 'DogApplication', create a class called 'Dog' 1. declare two instance variables in...

    In a project named 'DogApplication', create a class called 'Dog' 1. declare two instance variables in 'Dog' : name (String type) age (int type) 2. declare the constructor for the 'Dog' class that takes two input parameters and uses these input parameters to initialize the instance variables 3. create another class called 'Driver' and inside the main method, declare two variables of type 'Dog' and call them 'myDog' and 'yourDog', then assign two variables to two instance of 'Dog' with...

  • Congratulations, you have been hired by Shaky Bank and Trust as a staff programmer. Your task...

    Congratulations, you have been hired by Shaky Bank and Trust as a staff programmer. Your task for this assignment is to create a simple bank accounting system and demonstrate its use. Create an Account class as per the following specifications: three private instance variables: accountOwnerName (String), accountNumber (int) and balance (double) a single constructor with three arguments: the account owner's name, accountNumber and starting balance. In the constructor, initialize the instance variables with the provided parameter values. get and set...

  • Create an abstract class Employee. Your Employee class should include the following attributes: First name (string)...

    Create an abstract class Employee. Your Employee class should include the following attributes: First name (string) Last name (string) Employee id (string) Employee home street address (string) Employee home city (string) Employee home state (string) Write a constructor to initialize the above Employee attributes. Create an abstract method called earnings.      Create another class HourlyEmployee that inherits from the abstract Employee class.   HourEmployee must use the inherited parent class variables and add in attributes HourlyRate and HoursWorked. Your HourEmployee class should...

  • Create an abstract class Employee. Your Employee class should include the following attributes: First name (string)...

    Create an abstract class Employee. Your Employee class should include the following attributes: First name (string) Last name (string) Employee id (string) Employee home street address (string) Employee home city (string) Employee home state (string) Write a constructor to initialize the above Employee attributes. Create an abstract method called earnings.      Create another class HourlyEmployee that inherits from the abstract Employee class.   HourEmployee must use the inherited parent class variables and add in attributes HourlyRate and HoursWorked. Your HourEmployee class should...

  • Part (A) Note: This class must be created in a separate cpp file Create a class...

    Part (A) Note: This class must be created in a separate cpp file Create a class Employee with the following attributes and operations: Attributes (Data members): i. An array to store the employee name. The length of this array is 256 bytes. ii. An array to store the company name. The length of this array is 256 bytes. iii. An array to store the department name. The length of this array is 256 bytes. iv. An unsigned integer to store...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT