Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Employee
- {
- public class ApplicationUtilities
- {
- public static void DisplayApplicationInformation()
- {
- Console.WriteLine("Welcome to the Basic Employee Program");
- Console.WriteLine("CIS247a, Week 2 Lab");
- Console.WriteLine("Name: ");
- Console.WriteLine("This program accepts user input as a string, then makes the \nappropriate data conversion and assigns the value to Employee objects");
- Console.WriteLine();
- }
- public static void DisplayDivider(string outputTitle)
- {
- Console.WriteLine("\n********* " + outputTitle + " *********\n");
- }
- public static void TerminateApplication()
- {
- DisplayDivider("Program Termination");
- Console.Write("Thank you. Press any key to terminate the program...");
- Console.ReadLine();
- }
- public static void PauseExecution()
- {
- Console.Write("\nProgram paused, press any key to continue...");
- Console.ReadLine();
- Console.WriteLine();
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace
- Employee
- {
- class Employee
- {
- public string firstName = "not given";
- public string lastName = "not given";
- public char gender = 'U';
- public int dependants = 0;
- public double annualSalary = 20000;
- public double weeklyPay = 0;
- public Employee()
- {
- }
- public Employee(string firstName, string lastName, char gender, int dependants, double annualSalary, double weeklyPay)
- {
- this.firstName = firstName;
- this.lastName = lastName;
- this.gender = gender;
- this.dependants = dependants;
- this.annualSalary = annualSalary;
- this.weeklyPay = CalculateWeeklyPay();
- }
- public double CalculateWeeklyPay()
- {
- double wPay;
- wPay = annualSalary / 52; //weekly pay is annual salary divided by 52
- return wPay;
- }
- public override string ToString()
- {
- string output;
- output =
- "======Employee Information=========\n" + //This will output once the information is given
- " Name: " + firstName + " " + lastName + "\n" +
- " Gender: " + gender + "\n" +
- " Depednants: " + dependants + "\n" +
- "Annual Salary: " + annualSalary + "\n" +
- " Weekly Pay: " + CalculateWeeklyPay();
- return output;
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Employee
- {
- public class InputUtilities
- {
- public static string GetInput(string inputType)
- {
- string strInput = String.Empty;
- Console.Write("Enter your " + inputType + ": ");
- strInput = Console.ReadLine();
- return strInput;
- }
- public static string getStringInputValue(string inputType)
- {
- string value = String.Empty;
- bool valid = false;
- string inputString = String.Empty;
- do
- {
- inputString = GetInput(inputType);
- if (!String.IsNullOrEmpty(inputString))
- {
- value = inputString;
- valid = true;
- }
- else
- {
- value = "Invalid input";
- valid = false;
- }
- if (!valid)
- Console.WriteLine("Invalid " + inputType + " try again!");
- } while (!valid);
- return value;
- }
- public static int getIntegerInputValue(string inputType)
- {
- bool valid = false;
- int value = 0;
- string inputString = String.Empty;
- do
- {
- inputString = GetInput(inputType);
- if (!(String.IsNullOrEmpty(inputString)))
- {
- valid = Int32.TryParse(inputString, out value);
- }
- if (!valid)
- Console.WriteLine("Invalid " + inputType + " try again!");
- } while (!valid);
- return value;
- }
- public static double getDoubleInputValue(string inputType)
- {
- bool valid = false;
- double value = 0;
- string inputString = String.Empty;
- do
- {
- inputString = GetInput(inputType);
- if (!(String.IsNullOrEmpty(inputString)))
- {
- valid = Double.TryParse(inputString, out value);
- }
- if (!valid)
- Console.WriteLine("Invalid " + inputType + " try again!");
- } while (!valid);
- return value;
- }
- public static char getCharInputValue(string inputType)
- {
- bool valid = false;
- char value = 'u';
- string inputString = String.Empty;
- do
- {
- inputString = GetInput(inputType);
- if (!(String.IsNullOrEmpty(inputString)))
- {
- valid = Char.TryParse(inputString, out value);
- }
- if (!valid)
- Console.WriteLine("Invalid " + inputType + " try again!");
- } while (!valid);
- return value;
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Employee
- {
- public class Program
- {
- public static void Main(string[] args)
- {
- ApplicationUtilities.DisplayApplicationInformation(); //Displays Program Information
- ApplicationUtilities.DisplayDivider("START PROGRAM");
- ApplicationUtilities.DisplayDivider("PROMPT FOR EMPLOYEE INFORMATION AND CREATE FIRST EMPLOYEE");
- Employee emp1 = new Employee(); //Information for Employee #1
- emp1.firstName =
- InputUtilities.getStringInputValue("First name");
- emp1.lastName =
- InputUtilities.getStringInputValue("last name");
- emp1.gender =
- InputUtilities.getCharInputValue("Gender");
- emp1.dependants =
- InputUtilities.getIntegerInputValue("# of dependants");
- emp1.annualSalary =
- InputUtilities.getDoubleInputValue("Annual salary");
- Console.WriteLine(emp1);
- ApplicationUtilities.PauseExecution(); //Pause
- Employee emp2 = new Employee("John", "Smith", 'm', 2, 50000, 50000/52);
- Console.WriteLine(emp2);
- ApplicationUtilities.TerminateApplication(); //Closes the Application
- }
- }
- }
Add Comment
Please, Sign In to add comment