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

  Compare activity of disk required for each of the relational

Compare the activity (quite theoretical) of the disk (in number of bytes) required for each of both relational. Indicate the advantages and the inconveniences of the new relational scheme.

  Explaining laws dealing with computer crimes

Write and explain three recent laws dealing with computer crimes.

  Write and explain briefly three guidelines for sound policy

Write and explain briefly three guidelines for sound policy, as stated by Bergeron and Bérubé. Are policies different from standards? In what way? Are policies different from procedures? In what way?

  Determine minimum number of element

We wish to find the element x that is in upper half when S is sorted, or in other words element which is greater than median. Determine the minimum number of element comparision required to solve problem ?

  Solving problem by permutation on set is a one-to-one

Prove that PERM=POWER P, the obvious algorithm doesn't run in polynomial time as problem size is logarithmic (and no linear) with respect to the value of t.

  Write an overloaded lineup method

The players in a line-up must be unique. Write an overloaded LineUp method that writes a line-up to an output stream.

  Which of these two versions do you prefer and why

Redraw the ERD for this new situation using two entity types, and the redraw it again using one entity type. Which of these two versions do you prefer and why?

  Compare results search and identify any differences

There are several options of search engines, including Yahoo, Google, DogPile, and Maholo. Using the listed search engines above, search for something that interest you

  Web page makes effective and consistent use of headings

Use search engine to determine the example of Web page which makes effective and consistent use of headings to organize Web page content.

  Program to clear register a

Write a program to clear Register A, add five to Register A 10 times, and place the result in RAM Location $2000. Use a RAM location for holding the counter.

  Suppose a c++ compiler for the mips

Suppose a C++ compiler for the MIPS machine associates $s5 with array a and $s6 with variable i. How does it translate a[i] = a[i+1]; into MIPS assembly language?

  Explaining records are stored and accessed on storage medium

Which of the given correctly explains a way in which data records are stored and accessed on storage medium?

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