Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

Write a class called Employee that has the following fields:

? name - the name field references a String object that holds the employee's name.

? idNumber - the idNumber is an int variable that holds the employee's ID number.

? 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:

o 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.

o A no-argument constructor that assigns empty strings ("") to the name, department, and position fields and 0 to the idNumber field.

Also write appropriate accessor and mutator methods for each field.

Finally, write an appropriate toString() method that prints the state of the object. Example: Name: Mark Jones ID Number: 39119 Department: IT Position: Programmer

 

/*

 

For this program, you should write:

- A constructor that initializes the fields

1) name

2) ID

3) department

4) position

- A no argument constructor

- Mutator methods for each field

 

*/

import java.util.*;

 

public class Lab12Driver

{

public static void main(String [] args)

{

Scanner inScan=new Scanner(System.in);

// Reads the name

System.out.println("Enter employee's Name: ");

String name=inScan.nextLine();

// Reads the ID Number

System.out.println("Enter employee's ID Number: ");

int ID=inScan.nextInt();

// Om nom nom

// Flush the buffer

inScan.nextLine();

// Reads the department

System.out.println("Enter employee's department: ");

String dept=inScan.nextLine();

// Reads the position

System.out.println("Enter employee's position: ");

String pos=inScan.nextLine();

// Use the constructor

Employee firstGuy=new Employee(name,ID,dept,pos);

System.out.println(firstGuy);

// Use the empty constructor

Employee emptyGuy=new Employee();

// Use the mutator methods to fill the fields

emptyGuy.setName("Fred");

emptyGuy.setID(9001);

emptyGuy.setDepartment("Fred");

emptyGuy.setPosition("Underwater Basket Weaver");

System.out.println(emptyGuy);

}

}

 

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M9887508

Have any Question?


Related Questions in Computer Engineering

Question suppose you are asked to automate the prescription

Question : Suppose you are asked to automate the prescription fulfillment system for a pharmacy, MailDrugs. When an order comes in, it is given as a sequence of requests, "x1 ml of drug y1," "x2 ml of drug y2," "x3 ml of ...

In statistics the mode of a set of values is the value that

In statistics, the mode of a set of values is the value that occurs most often or with the greatest frequency. Write a function that accepts as arguments the following: A. An array of integers B. An integer that indicate ...

A firm produces product a and product b this years sales

A firm produces Product A and Product B. This years sales price of Product A have decreased tremendously, and the sale of Product B has increase by 10 percent. The firm has threeemployees that can produce Product A and f ...

Question suppose you want to achieve a speedup of 90 times

Question : Suppose you want to achieve a speedup of 90 times faster with 100 processors. What percentage of the original computation can be sequential? Assume one byte data value is 1101, 1000(binary). When we decode the ...

Video and disruption report assignmentoverviewfor this

Video and Disruption Report Assignment Overview For this assessment task, you will create a two-minute video and written proposal about the impact of a particular technology on an industry or field. The purpose of this a ...

A sequence of natural numbers a1 a2 an is said to be a

A sequence of natural numbers (a 1 , a 2 , ..., a n ) is said to be a degree sequence if there exists an undirected graph on n vertices {v 1 , v 2 , ..., v n } such that the degree of v i  is a i  for each i = 1, 2, ..., ...

Scruffie the cat has 15 to spend each month on cat toys

Scruffie the cat has $15 to spend each month on cat toys, which cost $3 each, and cat treats, which cost $1.50 each. Draw a budget line to show the combination of each good that scuffie can afford if she spends her entir ...

Question the project presentation should demonstrate

Question: The project presentation should demonstrate knowledge in the chosen area. The presentation should be formatted as follows: 12-point font using Times New Roman Use APA style correctly throughout the presentation ...

Mary kate is a project manager in the it department for a

Mary Kate is a project manager in the IT department for a university. She has been asked to manage a project to create faculty intranet. The university has multiple campuses in various locations, and professors and other ...

Compare remote authentication dial-in user service radius

Compare Remote Authentication Dial-In User Service (RADIUS) and Terminal Access Controller Access-Control System Plus (TACACS+).

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As