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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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

Expert Solution
Employee.java

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

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Unreferenced Objects
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education