70 likes | 82 Views
Exercise 2. Introduction to C# CIS-2320. Create a class called Employee that contains the following private instance variables: Social Security string Name string Pay float Type char (‘ H ’= Hourly ‘ S ’ = Salaried) Provide three constructors: Employee()
E N D
Exercise 2 Introduction to C# CIS-2320
Create a class called Employee that contains the following private instance variables: Social Security string Name string Pay float Type 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.
In order to store and process objects of the type Employee create a class called Employees. This class uses a instance of the ArrayListclass to storeEmployee 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.
public void ListAllEmployees() This method produces a listing of the employees currently in the ArrayList object. It should be in social security number sequence. 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 an argument. 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() method of 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.
public void ListByName()(Extra 3 points) This method sorts the ArrayList in sequence by employee name and displays the employees currently in the ArrayList. Do not change the current order of the employees (social security number sequence) in the ArrayList.
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 employee 2 = Add salaried employee 3 = Display employee 4 = Delete employee 5 = List all employees 6 = 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’.
Create a test class called Exercise2. The Main() method should look as follows: static void Main(string[] args) { Menu EmpMenu = new Menu(); EmpMenu.Process(); }