Create a class named Employee. The class must contain private member variables: name and salary. It should contain getter methods for returning the name and salary. It should also contain setter methods for setting the name and salary. The class must include a constructor, the constructor must be designed to set both the name and the salary. In addition, the Employee class must contain a toString() method that prints both name and salary.
Create a class named Employee. The class must contain private
member variables: name and salary. It should contain getter
methods for returning the name and salary. It should also contain
setter methods for setting the name and salary. The class must
include a constructor, the constructor must be designed to set both
the name and the salary. In addition, the Employee class must
contain a toString() method that prints both name and salary.
Create a class named Test. The class must contain the main
method. In the main method, you should create three objects from
class Employee and store them in an array of type Employee (you
must prompt the user to enter name and salary for each object).
Then, you should print the name and salary of each object (using
either the getters or the toStrong() method).
DO NOT COPY CHEGG
public class Employee
{
//declaring instance variables as private
private String name;
private double salary;
//getters
public String getName()
{
return this.name;
}
public double getSalary()
{
return this.salary;
}
//setters
public void setName(String name)
{
this.name=name;
}
public void setSalary(double salary)
{
this.salary=salary;
}
//parameterized constructor
public Employee(String name, double salary)
{
setName(name);
setSalary(salary);
}
public String toString()
{
return "Name: "+name+"\tSalary: "+salary;
}
}
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images