Write a class called employee that has the following fields

Assignment Help Basic Computer Science
Reference no: EM13308190

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);

}

}

 

Reference no: EM13308190

Questions Cloud

How many hits does the sequence exhibit : Assume LRU replacement policy, for each sequence, how many hits does the sequence exhibit?
Explain digital computing/networking in major organizations : Identify and discuss at least three major evolutionary steps in digital computing/networking experienced in major organizations. If possible, provide such insight regarding your current or former organization.
How many data in the number of bytes can be hold in cache : What is the size of the cache, i.e., how many data in the number of bytes can be hold in the cache?
How much does the water in the cloud weigh in pounds : Often this content is measured in grams per cubic meter (g/m3). Assume that a cumulus cloud occupies a volume of one cubic kilometer, and its liquid water content is 0.210 g/m3.
Write a class called employee that has the following fields : Finally, write an appropriate toString() method that prints the state of the object. Example: Name: Mark Jones ID Number: 39119 Department: IT Position: Programmer
Determine the required are of concrete for the thrust block : Given that the max shear strength of the the concrete shore is 10 kPa and the engineer requires a F.S. of 2.5, find the required are of concrete for the thrust block.
Determine what is the pressure in the pipe at floor level : A water storage tank is on the roof of a factory building & the surface of the water is 50 ft above the floor of the factory. if a pipe connects the storage tank to the floor level & the pipe is full of static water
Declare a variable : Assume the existence of a Window class with methods getWidth and getHeight, and a subclass TitledWindow, with a constructor accepts a string corresponding to the title of the window.
Find the expected number of jobs in the system at any time : An M/M/1 queuing system spends 30% of the time in the idle state. Find the expected number of jobs in the system at any time.

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Identities of peers in the range

I shall create a new question for you to post up your answer so you can earn the points you deserve for helping me out.

  Make the color of the text lightblue

Write a CSS rule that gives h1 and h2 elements a padding of 0.5 ems, a dashed border style and a margin of 0.5 ems.

  What is primary security risk users acknowledge using macros

Write a 200- to 300-word response that answers the following question: Based on the article by Lenning (2005), what is a primary security risk that users should acknowledge when using macros?

  Display the new list as well as the two old list

Display the new list as well as the two old list Thank you in advance.

  Calculate the relative return on investment

Calculate the relative return on investment if I want to invest in a company

  Write a version of sum pairs i that sums each component

Using SML write a version of sumPairs that sums each component of the pairs separately, returning a pair consisting of the sumof the first components and the sum of the second components

  Write procedure endian return 1compiled and 0 bigendian

Write a procedure is little endian that will return 1 when compiled and run on a little-endian machine, and will return 0 when compiled and run on a bigendian machine.

  Add the following numbers in two''s complements

Given four bits, add the following numbers in two's complements. a. - 4 + (- 1), b. -7 + 3, c. -5 + 4

  Explain different kinds of feasibility studies

When deciding whether to buy and implement digital dashboard or management cockpit sometimes a feasibility study is conducted.  Explain the different kinds of feasibility studies.

  How do you add all the elements of an arraylist

how do you add all the elements of an ArrayList favorite? I need help on creating class and client.

  Write program mips assembly adds two integer and display sum

Write a MIPS assembly language program that adds two integers and displays the sum and the difference.

  Using jflap construct a turing machine

Using JFLAP construct a turing machine that does integer division for numbers in unary notation. For example your machine should execute the calculation

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd