Knowee
Questions
Features
Study Tools

[25 points] Write a Java class named Employee such that the class contains threeattributes empName, salary, and departmentName. You should be able to createobjects of this class by supplying values to any one, two, or all three of the attributes. Ifno value is supplied during the object creation, the attributes should be initialized withsome default values. You are expected to use 'this' keyword to achieve the result. Discussthe ways in which you can change or reset the attribute values of the objects created.Write appropriate mutator methods that store values in these fields and accessormethods that return the values in these fields. Once you have written the class, write aseparate program that creates three Employee objects to hold the following data:Employee Name Department Salary---------------------------------------------------------------------Susan Meyers Accounting 5000.00Mark Jones IT 8375.00Joy Rogers Manufacturing 6380.00---------------------------------------------------------------------The program should store this data in the three objects and then display the data for eachemployee on the screen

Question

[25 points] Write a Java class named Employee such that the class contains threeattributes empName, salary, and departmentName. You should be able to createobjects of this class by supplying values to any one, two, or all three of the attributes. Ifno value is supplied during the object creation, the attributes should be initialized withsome default values. You are expected to use 'this' keyword to achieve the result. Discussthe ways in which you can change or reset the attribute values of the objects created.Write appropriate mutator methods that store values in these fields and accessormethods that return the values in these fields. Once you have written the class, write aseparate program that creates three Employee objects to hold the following data:Employee Name Department Salary---------------------------------------------------------------------Susan Meyers Accounting 5000.00Mark Jones IT 8375.00Joy Rogers Manufacturing 6380.00---------------------------------------------------------------------The program should store this data in the three objects and then display the data for eachemployee on the screen

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

Here is the Java code for the Employee class:

public class Employee {
    private String empName;
    private double salary;
    private String departmentName;

    // Constructor with no arguments
    public Employee() {
        this("Default Name", 0.0, "Default Department");
    }

    // Constructor with one argument
    public Employee(String empName) {
        this(empName, 0.0, "Default Department");
    }

    // Constructor with two arguments
    public Employee(String empName, double salary) {
        this(empName, salary, "Default Department");
    }

    // Constructor with three arguments
    public Employee(String empName, double salary, String departmentName) {
        this.empName = empName;
        this.salary = salary;
        this.departmentName = departmentName;
    }

    // Mutator methods
    public void setEmpName(String empName) {
        this.empName = empName;
    }

    public void setSalary(double salary) {
        this.salary = salary;
    }

    public void setDepartmentName(String departmentName) {
        this.departmentName = departmentName;
    }

    // Accessor methods
    public String getEmpName() {
        return empName;
    }

    public double getSalary() {
        return salary;
    }

    public String getDepartmentName() {
        return departmentName;
    }
}

And here is the separate program that creates three Employee objects:

public class Main {
    public static void main(String[] args) {
        Employee employee1 = new Employee("Susan Meyers", 5000.00, "Accounting");
        Employee employee2 = new Employee("Mark Jones", 8375.00, "IT");
        Employee employee3 = new Employee("Joy Rogers", 6380.00, "Manufacturing");

        System.out.println("Employee Name: " + employee1.getEmpName() + ", Salary: " + employee1.getSalary() + ", Department: " + employee1.getDepartmentName());
        System.out.println("Employee Name: " + employee2.getEmpName() + ", Salary: " + employee2.getSalary() + ", Department: " + employee2.getDepartmentName());
        System.out.println("Employee Name: " + employee3.getEmpName() + ", Salary: " + employee3.getSalary() + ", Department: " + employee3.getDepartmentName());
    }
}

This program will display the data for each employee on the screen.

This problem has been solved

Similar Questions

21. Write a Java program that creates a class hierarchy for employees of a company. The base class should be Employee, with subclasses Manager, Developer, and Programmer. Each subclass should have properties such as name, address, salary, and job title. Implement methods for calculating bonuses, generating performance reports, and managing projects

Design a class named Person and its two subclasses named Student and Employee.  Make Faculty and Staff subclasses of Employee. A person has a name,  address, phone_number, and e-mail address. A student has a status (freshman, sophomore, junior, or senior).  An employee  has an office, salary. A faculty member has office_hours and a rank. A staff member has a title. Override the toString() method in each of these classes to display their details. Write a Java application and subsequent pseudocode to implement/simulate the same.

Arrange the code shuffle provided such that -   first you provide the no argument constructor that prints "In default constructor" , -   next is the constructor with id, name and salary as arguments that invokes the no arg constructor and sets the attributes passed as attribute and -   finally the constructor with id, name, salary and pancardno as arguments that invokes the 3 argument constructor and then sets the pancardno.public class Employee {public Employee(){private int id;private String name;private float salary;private String pancardno;}this();public Employee(int id, String name, float salary) {this.id = id;this.name = name;this.salary = salary;} this.pancardno = pancardno; }this(id,name,salary);System.out.println("In default constructor");}public Employee(int id, String name, float salary, String pancardno) {

Q1. Create an Employee class with the relevant attributes and methods in addition of thefollowing specifications:  It contains a default constructor. It contains a parameterized constructor. It contains a copy constructor.Note: Each student should have different their own version and it is better to have morethe attributes and methods.Q2. Incorporate static attributes and static methods in the Employee class where required.note for chatgpt/bard : computer languages used for code is c#

Sarah got confused to creating the constructor. Write a Java application to help Sarah to do this.Type(Class)AttributesMethodsResponsibilitiesStudentint studentIdString studentNameString studentAddressString collegeNameInclude the getters and setters method for all the attributes.  Student Include a public parametrized constructor of four arguments in the following order - studentId, studentName, studentAddress, and collegeName to initialize the values for the Student objectIf student belongs to other college, give input as 'no/NO' and get college name from the user and create student object with 4-argument constructor to initialize all the values.  Student Include a public parametrized constructor of three arguments in the following order - studentId, studentName, studentAddress, and collegeName should be "NIT" to initialize the values for the Student objectIf student belongs to NIT, give input as 'yes/YES' and skip input for the attribute collegeName and create student object with 3-argument constructor to initilze the values for studentId, studentName and studentAddress and  collegeName as "NIT".  Note: The class and methods should be declared as public and all the attributes should be declared as private.  In the UserInterface class, write the main method to test the application.Assume most of the students are from "NIT" college. So user has to give input whether the student is from NIT or not.Instead of Yes / No, if user enters different input then display 'Wrong Input' and get the input again. Note:In the Sample Input / Output provided, the highlighted text in bold corresponds to the input given by the user, and the rest of the text represents the output.Ensure to follow the object-oriented specifications provided in the question description.Ensure to provide the names for classes, attributes, and methods as specified in the question description.Adhere to the code template, if provided.Please do not use System.exit(0) to terminate the program. Sample Input 1:Enter Student's Id:12Enter Student's Name:JohnEnter Student's address:ChennaiWhether the student is from NIT(Yes/No):NOEnter the college name:SVS Sample Output 1:Student id:12Student name:JohnAddress:ChennaiCollege name:SVS Sample Input 2:Enter Student's Id:43Enter Student's Name:TomEnter Student's address:CoimbatoreWhether the student is from NIT(Yes/No):yWrong InputWhether the student is from NIT(Yes/No):yes Sample Output 2:Student id:43Student name:TomAddress:CoimbatoreCollege name:NIT

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.