Question

In: Computer Science

Using C#: Write a class named Employee that has the following properties: Name - The Name...

Using C#:

Write a class named Employee that has the following properties:

  • Name - The Name property holds the employee's name
  • IdNumber - The IdNumber property holds the employee's ID number
  • Department - The Department property holds the name of the department in which the employee works
  • Position - The Position property holds the employee's job title

The class should have the following overloaded constructors:

  • A constructor that accepts the following values as arguments and assigns them to the appropriate properties: 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 properties:employee's name and ID number. The Department and Position properties should be assigned an empty string (" ")
  • A parameterless constructor that assigns the empty string (" ") to the Name, Department, and Position properties, and 0 to the IdNumber property

In an application, create three Employee objects to hold the following data:

Name                         IdNumber                           Department                    Position

Susan Myers               47899                                 Accounting                     Vice President

Mark Jones                 39119                                 IT                                  Programmer

Joy Rogers                  81774                                 Manufacturing                Engineer

The application should store this data in the three objects and display the data for each employee on the screen.

Solutions

Expert Solution

Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Employee_Class
{
class Employee
{
private string Name, Department, Position;
private int IdNumber;
public Employee(string name, int id, string dept, string pos)
{
Name = name;
Department = dept;
IdNumber = id;
Position = pos;
}
public Employee(string name, int id)
{
Name = name;
Department = "";
IdNumber = id;
Position = "";
}
public Employee()
{
Name = "";
Department = "";
IdNumber = 0;
Position = "";
}
public override string ToString()
{
String data = String.Format("{0,-20} {1,-15} {2,-25} {3, -10}",Name,IdNumber,Department,Position);
return data;
}
}
class Program
{
static void Main(string[] args)
{
String output = String.Format("{0,-20} {1,-15} {2,-25} {3, -10} ", "Name", "IdNumber", "Department", "Position");
Employee e1 = new Employee("Susan Myers", 47899, "Accounting", "Vice President");
Employee e2 = new Employee("Mark Jones ", 39119, "IT", "Programmer");
Employee e3 = new Employee("Joy Rogers", 81774, "Manufacturing ", "Engineer");

Console.WriteLine(output);
Console.WriteLine(e1);
Console.WriteLine(e2);
Console.WriteLine(e3);
}
}
}

output

If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.


Related Solutions

using C++ Please create the class named BankAccount with the following properties below: // The BankAccount...
using C++ Please create the class named BankAccount with the following properties below: // The BankAccount class sets up a clients account (using name & id), and - keeps track of a user's available balance. - how many transactions (deposits and/or withdrawals) are made. public class BankAccount { private int id; private String name private double balance; private int numTransactions; // ** Please define method definitions for Accessors and Mutators functions below for the class private member variables string getName();...
In C# thanks please, Design a class named Person with properties for holding a person’s name,...
In C# thanks please, Design a class named Person with properties for holding a person’s name, address, and telephone number. Design a class named Customer, which is derived from the Person class. The Customer class should have the variables and properties for the customer number, customer email, a spentAmount of the customer’s purchases, and a Boolean variable indicating whether the customer wishes to be on a mailing list. It also includes a function named calcAmount that calculates the spentAmount. All...
Write in C++ language. (Employee Record): Create a class named 'Staff' having the following members: Data...
Write in C++ language. (Employee Record): Create a class named 'Staff' having the following members: Data members - Id – Name - Phone number – Address - AgeIt also has a function named 'printSalary' which prints the salary of the staff.Two classes 'Employee' and 'Officer' inherits the 'Staff' class. The 'Employee' and 'Officer' classes have data members 'Top Skill' and 'department' respectively. Now, assign name, age, phone number, address and salary to an employee and a officer by making an...
~~~USING C# ONLY~~~ Create a console application Design a class named Person with properties for holding...
~~~USING C# ONLY~~~ Create a console application Design a class named Person with properties for holding a person’s name, address, and telephone number. Design a class named Customer, which is derived from the Person class. The Customer class should have the variables and properties for the customer number, customer email, a spentAmount of the customer’s purchases, and a Boolean variable indicating whether the customer wishes to be on a mailing list. It also includes a function named calcAmount that calculates...
The Account class Create a class named Account, which has the following private properties:
in java The Account class Create a class named Account, which has the following private properties: number: long balance: double Create a no-argument constructor that sets the number and balance to zero. Create a two-parameter constructor that takes an account number and balance. First, implement getters and setters: getNumber (), getBalance (), setBalan newBalance). There is no setNumber () once an account is created, its account number cannot change. Now implement these methods: void deposit (double amount) and void withdraw (double amount). For both these methods, if the amount is less than...
The Account class Create a class named Account , which has the following private properties:
 The Account class Create a class named Account , which has the following private properties: number: long balance: double Create a no-argument constructor that sets the number and balance to zero. Create a two-parameter constructor that takes an account number and balance. First, implement getters and setters: getNunber(), getBalance(), setBalance (double newBalance) . There is no setNunber() - once an account is created, its account number cannot change. Now implement these methods: void deposit (double anount) and void withdraw(double anount). For both these methods, if the amount is less than zero,...
Design a class named Employee. The class should keep the following information in fields: ·         Employee...
Design a class named Employee. The class should keep the following information in fields: ·         Employee name ·         Employee number in the format XXX–L, where each X is a digit within the range 0–9 and the L is a letter within the range A–M. ·         Hire date Write one or more constructors and the appropriate accessor and mutator methods for the class. Next, write a class named ProductionWorker that inherits from the Employee class. The ProductionWorker class should have fields...
Write a Data Element Class named Property that has fields tohold the property name, the...
Write a Data Element Class named Property that has fields to hold the property name, the city where the property is located, the rent amount, the owner's name, and the Plot to be occupied by the property, along with getters and setters to access and set these fields. Write a parameterized constructor (i.e., takes values for the fields as parameters) and a copy constructor (takes a Property object as the parameter). Follow the Javadoc file provided.Write a Data Element Class...
Write a class named ContactEntry that has fields for a person’s name, phone number and email...
Write a class named ContactEntry that has fields for a person’s name, phone number and email address. The class should have a no-arg constructor and a constructor that takes in all fields, appropriate setter and getter methods. Then write a program that creates at least five ContactEntry objects and stores them in an ArrayList. In the program create a method, that will display each object in the ArrayList. Call the method to demonstrate that it works. I repeat, NO-ARG constructors....
The Account class Create a class named Account, which has the following private properties: number: long...
The Account class Create a class named Account, which has the following private properties: number: long balance: double Create a no-argument constructor that sets the number and balance to zero. Create a two-parameter constructor that takes an account number and balance. First, implement getters and setters: getNumber(), getBalance(), setBalance(double newBalance). There is no setNumber() -- once an account is created, its account number cannot change. Now implement deposit(double amount) and withdraw(double amount) methods. If the amount is less than zero,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT