1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Step2247 [10]
3 years ago
14

Use Java to write a class named Employee that has the following fields: name - The name field references a String object that ho

lds the employee's name; idNumber - The idNumber is an int variable that holds the employee's ID number department; department - The department field references a String object that holds the name of the department where the employee works; position - The position field references a String object that holds the employee's job title.
The class should have the following constructors: A constructor that accepts the following values as arguments and assigns them to the appropriate fields employee's name, employee's ID number, department, and position. A constructor that accepts the following values as arguments and assigns them to the appropriate fields: employee's name and ID number. The department, and position fields should be assigned an empty string (" "). A no-arg constructor that assigns empty strings (" ") to the name, department, and position fields, and 0 to the idNumber field.

Write appropriate mutator methods that store values in these fields and accessor methods that return the values in these fields. Once you have written the class, write a separate program the creates three Employee objects to hold the following data: Name ID Number Department Position Susan Meyers 47899 Accounting Vice President Mark Jones 39119 IT Programmer Joy Rogers 81774 Manufacturing Engineer.

The program should store this data in three objects and then display the data for each employee on the screen.
Computers and Technology
1 answer:
myrzilka [38]3 years ago
8 0

Answer:

Hi Mitutk! Very good question for Java programmers to test knowledge on classes, constructors and mutator methods. Please find the answer with explanation below.

Explanation:

Constructors in Java can be declared with different parameters. Declaring the properties of the Employee object as private, such as the name, id, department and position as in this example, is good design practice as it helps to keep data secure. We can get and set these properties by accessor methods as declared below. The second program can be written a few different ways, try using the set methods for storing the different info instead of the constructors used.

 

Employee.java

class Employee {

 private String employeeName;

 private int idNumber;

 private String department;

 private String position;

 public Employee() {

   employeeName = "";

   idNumber = 0;

   department = "";

   position = "";

 }

 public Employee(String name, int id, String dept, String pos) {

   employeeName = name;

   idNumber = id;

   department = dept;

   position = pos;

 }

 public Employee(String name, int id) {

   employeeName = name;

   idNumber = id;

   department = "";

   position = "";

 }

 public void set_employee_name(String empName) {

   employeeName = empName;

 }

 public String get_employee_name() {

   return employeeName;

 }

 public void set_employeeId(int empId) {

   idNumber = empId;

 }

 public int get_employeeId() {

   return idNumber;

 }      

       

 public void set_department(String dept) {

   department = dept;

 }          

 public String get_department() {

   return department;

 }

   

 public void set_position(String pos) {

   position = pos;

 }

   

 public String get_position() {

   return position;

 }

}

EmployeeProgram.java

import Employee.java;

public class EmployeeProgram {

 public static void main(String args[]) {

   Employee emp1 = new Employee("Susan Meyers", 47899, "Accounting", "Vice President");

   Employee emp2 = new Employee("Mark Jones", 39119, "IT", "Programmer");

   Employee emp3 = new Employee("Joy Rogers", 81774, "Manufacturing", "Engineer");

   System.out.println(emp1.get_employee_name());

   System.out.println(emp2.get_employee_name());

   System.out.println(emp3.get_employee_name());

 }

}

You might be interested in
The____ option lets you add space above each paragraph without changing the paragraph spacing.
Delvig [45]

The line and spacing command

6 0
4 years ago
Cloud-based services can open doors to leveraging Artificial Intelligence (AI) without dramatically increasing risk. Which clien
vladimir1956 [14]

Answer:

Explanation:

The clients that would be best suited for this opportunity would be small business or business' that do not have the hardware/space resources necessary to create the computing power that they need. Instead, they can simply pay for these cloud-based services which provide all of the necessary computing/hardware power and resources necessary so that the company can easily fulfill all of their tasks without any problems. Bigger companies can easily pay for and implement their own hardware to solve their problems which may benefit them even more in the long-term.

7 0
3 years ago
You are designing a wireless network for a client. your client needs the network to support a data rate of at least 54 mbps. in
vitfil [10]
Um... that is hard to explain Idk
5 0
4 years ago
Lief wants to keep the information of his chart, but he doesn’t want it taking up space in his page. What should he select after
Murljashka [212]
If wants to keep the chart but does not want it taking up space, he can move it  to another sheet. Once he goes to the Move Chart tab, he should select New Sheet which will ask for a name of the new sheet. After doing this, the chart will be moved to a different sheet.
4 0
4 years ago
Read 2 more answers
Pleas help with this question: Which statement about word processing software is true?
deff fn [24]
Short Answer C

The Primary use of any word processor is to create word documents (like this editor) with the ability to format it with bold letters or <u>underlining</u> or <em>italics</em>. There are many other choices of things to do. All your choices are true but the main one is the third one down.

It can do very simple mathematical calculations if it can create tables (neither of which is possible with this editor. A is incorrect.

D is mostly incorrect. Very few word processors have built in capabilities that would help you with word games. There are some that do. Most don't.

I would hate to create fonts using a word processor. It's remotely possible, but anyone in his right mind would try using a program designed for that.. B is incorrect.
8 0
4 years ago
Other questions:
  • What is returned by datetime(1970, 1, 1).strftime('%Y-%d-%B') in Python?
    10·1 answer
  • The web development team is having difficulty connecting by ssh to your local web server, and you notice the proper rule is miss
    8·1 answer
  • What type of hardward drive not require defragging??
    11·1 answer
  • The following slide was created as part of a presentation that trains new employees how to use the scheduling and calendar softw
    14·2 answers
  • Which term is used to describe individuals who want to attack computers yet lack the knowledge of computers and networks needed
    12·1 answer
  • What is the first step necessary to begin setting up a website once a host has been selected and paid?
    11·1 answer
  • In the negative side of the battery, there are millions and millions of _________.
    14·1 answer
  • An EULA usually takes the form of an electronic notification that appears when installing software. The user then has a choice t
    14·1 answer
  • Lol fortnite really going UwU and anime
    12·2 answers
  • You designed a program to find the midpoint of two points. Which step below corresponds to finding the average of the x-coordina
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!