7
Exercise 2 Exercise 2 Introduction to C# Introduction to C# CIS-2320 CIS-2320

Exercise 2 Introduction to C# CIS-2320. 2 Create a class called Employee that contains the following private instance variables: Social Securitystring

Embed Size (px)

Citation preview

Page 1: Exercise 2 Introduction to C# CIS-2320. 2 Create a class called Employee that contains the following private instance variables: Social Securitystring

Exercise 2Exercise 2

Introduction to C#Introduction to C#

CIS-2320CIS-2320

Page 2: Exercise 2 Introduction to C# CIS-2320. 2 Create a class called Employee that contains the following private instance variables: Social Securitystring

2

Create a class called Employee that contains the following private instance variables:

Social Security stringName stringPay floatType char (‘H’= Hourly ‘S’ = Salaried)

Provide three constructors:Employee()

Employee(string s, string n, float p, char t);

Employee(Employee e);

Provide read-only properties for each instance variable.

Provide a Display() method to display all the instance variables on one line.

Page 3: Exercise 2 Introduction to C# CIS-2320. 2 Create a class called Employee that contains the following private instance variables: Social Securitystring

3

In order to store and process objects of the type Employee create a class called Employees. This class uses a instance of the ArrayList class to store Employee objects. It also provides the following methods to process the employees:

public Employees() Creates an instance of ArrayList public void AddSalariedEmployee() This method prompts the user to enter the data for a salaried employee, creates an instance of the Employee class, and inserts the new employee into the ArrayList object in order to keep the objects in sequence by social security number. Make sure there are no duplicates. public void AddHourlyEmployee() This method prompts the user to enter the data for a salaried employee, creates an instance of the Employee class, and inserts the new employee into the ArrayList object in order to keep the objects in sequence by social security number. Make sure there are no duplicates.

Page 4: Exercise 2 Introduction to C# CIS-2320. 2 Create a class called Employee that contains the following private instance variables: Social Securitystring

4

public void ListAllEmployees()

This method produces a listing of the employees currently inthe ArrayList object. It should be in social security numbersequence. If the list is empty, display a message to that effect

private bool Find_Employee( string s)This method searches the ArrayList to try and find theEmployee object with the social security number passed as anargument. It returns true if found otherwise false.

public void DisplayEmployee()This method prompts the user to enter a social security

number and attempts to find that employee in the ArrayList (using the above method). If found, call the Display() methodof the Employee object otherwise display a not found message.

public void DeleteEmployee()This method prompts the user to enter a social security

number and attempts to find that employee in the ArrayList. If found, remove the Employee object from the ArrayList.Make sure only existing employees are deleted.

Page 5: Exercise 2 Introduction to C# CIS-2320. 2 Create a class called Employee that contains the following private instance variables: Social Securitystring

5

public void ListByName() (Extra 3 points)This method sorts the ArrayList in sequence by

employeename and displays the employees currently in the

ArrayList.Do not change the current order of the employees (social

security number sequence) in the ArrayList.

Page 6: Exercise 2 Introduction to C# CIS-2320. 2 Create a class called Employee that contains the following private instance variables: Social Securitystring

6

Create a Menu class with a default constructor that creates an object of the type Employees. Also provide the following methods: private void Choices()

This method displays a menu and obtains the user’s selection. For example:

What is the desired option?1 = Add hourly employee2 = Add salaried employee3 = Display employee4 = Delete employee5 = List all employees6 = Exit

public void Process()This method calls the Choices() method above to display

the menu and obtain the user’s selection. It then passes control to the appropriate method of the Employees object (add hourly employee, add salaried employee, display an employee , list all employees, and delete an employee). Stay in this function until the user enters a ‘6’.

Page 7: Exercise 2 Introduction to C# CIS-2320. 2 Create a class called Employee that contains the following private instance variables: Social Securitystring

7

Create a test class called Exercise2. The Main() method should look as follows:

static void Main(string[] args) {

Menu EmpMenu = new Menu();

EmpMenu.Process();

}