JunkieHF

C# Gets and displays employee info, benefits, and pay

Aug 3rd, 2014
542
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 16.62 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace CIS247A_Employee
  7. {
  8.     public class ApplicationUtilities
  9.     {
  10.         //Displays information about the program
  11.         public static void DisplayApplicationInformation()
  12.         {
  13.             Console.WriteLine("Overloaded Methods and Statice Members");
  14.             Console.WriteLine("CIS247a, Week 4 Lab");
  15.             Console.WriteLine("Name: Junkie");
  16.             Console.WriteLine("This program accepts user input as a string, then makes the \nappropriate data conversion and assigns the value to Employee objects");
  17.             Console.WriteLine();
  18.         }
  19.         public static void DisplayDivider(string outputTitle)
  20.         {
  21.             Console.WriteLine("\n********* " + outputTitle + " *********\n");
  22.         }
  23.        //Closes the application
  24.         public static void TerminateApplication()
  25.         {
  26.             DisplayDivider("Program Termination");
  27.             Console.Write("Thank you.  Press any key to terminate the program...");
  28.             Console.ReadLine();
  29.         }
  30.         //Pauses the application
  31.         public static void PauseExecution()
  32.         {
  33.             Console.Write("\nProgram paused, press any key to continue...");
  34.             Console.ReadLine();
  35.             Console.WriteLine();
  36.         }
  37.     }
  38. }
  39.  
  40.  
  41.  
  42.  
  43. using System;
  44. using System.Collections.Generic;
  45. using System.Linq;
  46. using System.Text;
  47.  
  48. /******************************************************************
  49.  * Course:  CIS247A
  50.  * Week: 4
  51.  * Programmer:  Junkie
  52.  * Date: 8/2/2014
  53.  *
  54.  * Class Name:  Employee
  55.  * Class Description:
  56.  * The employee class stores the first and last name, annual salary,
  57.  * gender, and # of dependents. It makes sure that none of the values goes
  58.  * over the the maximum amount or under the minimum amount. It also calculates
  59.  * weekly pay and shows how the information will be displayed.
  60.  
  61. ***********************************************************************/
  62.  
  63.  
  64. namespace CIS247A_Employee
  65. {
  66.     public class Employee
  67.     {
  68.         public const double MIN_SALARY = 20000;
  69.         public const double MAX_SALARY = 100000;
  70.         public const int MIN_DEPENDENTS = 0;
  71.         public const int MAX_DEPENDENTS = 10;
  72.         public const string DEFAULT_NAME = "not given";
  73.  
  74.         private string firstName;
  75.         private string lastName;
  76.         private double annualSalary;
  77.         private char gender;
  78.         private int dependents;
  79.  
  80.       //since static, there will be only one copy of the number created variable
  81.         private static int numberEmployees = 0;
  82.            
  83.         public Employee()
  84.         {
  85.             FirstName = DEFAULT_NAME;
  86.             LastName = DEFAULT_NAME;
  87.             AnnualSalary = MIN_SALARY;
  88.             Dependents = MIN_DEPENDENTS;
  89.  
  90.             //make sure to increment number of employees each time a instance is created
  91.             numberEmployees += 1;
  92.         }
  93.         public Employee(string firstname, string lastname, char gender, int dependents, double salary)
  94.         {
  95.             FirstName = firstname;
  96.             LastName = lastname;
  97.             AnnualSalary = salary;
  98.             Gender = gender;
  99.             Dependents = dependents;
  100.  
  101.             //make sure to increment number of employees each time a instance is created
  102.             numberEmployees += 1;
  103.         }
  104.         public static int NumberOfEmployees
  105.         {
  106.             get { return numberEmployees; }
  107.         }
  108.         public string FirstName
  109.         {
  110.             get { return firstName; }
  111.             set
  112.             {
  113.                 if (String.IsNullOrEmpty(value)) //if string is empty then firstName = DEFAULT_NAME
  114.                     firstName = DEFAULT_NAME;
  115.                 else
  116.                     firstName = value; //if string is not empty then name = input value
  117.             }
  118.         }
  119.         public string LastName //last name is checked the same as first name
  120.         {
  121.             get { return lastName; }
  122.             set
  123.             {
  124.                 if (String.IsNullOrEmpty(value))
  125.                     lastName = DEFAULT_NAME;
  126.                 else
  127.                     lastName = value;
  128.             }
  129.         }
  130.         //if gender does not equal F or M then gender will be U. If gender = M or F then gender = input value
  131.         public char Gender
  132.         {
  133.             get { return gender; }
  134.             set
  135.             {
  136.                 char input;
  137.                 input = Char.ToUpper(value);
  138.                 if (input == 'F' || input == 'M')
  139.                     gender = input;
  140.                 else
  141.                     gender = 'U';
  142.             }
  143.         }
  144.         //if dependents is less than or greater than max_dependents (10) then dependents = max
  145.         // if dependents is less than min_dependents(0) then dependents = minimum
  146.         // else dependents = input value
  147.         public int Dependents
  148.         {
  149.             get { return dependents; }
  150.             set
  151.             {
  152.                 if (value >= MIN_DEPENDENTS && value <= MAX_DEPENDENTS)
  153.                     dependents = value;
  154.                 else if (value < MIN_DEPENDENTS)
  155.                     dependents = MIN_DEPENDENTS;
  156.                 else
  157.                     dependents = MAX_DEPENDENTS;
  158.             }
  159.         }
  160.         // if Annual Salary is less than minimum salary then annual salary is the minimum amount
  161.         // If annual salary is more than maximum salary then the annual salary is the maximum amount
  162.         // if annual salary is not less than minimum salary and not greater than maximum salary then annual salary = input value
  163.         public double AnnualSalary
  164.         {
  165.             get { return annualSalary; }
  166.             set
  167.             {
  168.                 if (value < MIN_SALARY)
  169.                     annualSalary = MIN_SALARY;
  170.                 else if (value > MAX_SALARY)
  171.                     annualSalary = MAX_SALARY;
  172.                 else
  173.                     annualSalary = value;
  174.             }
  175.         }
  176.         public string EmployeeName
  177.         {
  178.             get { return FirstName + " " + LastName; }
  179.         }
  180.         public double CalculateWeeklyPay()
  181.         {
  182.             return AnnualSalary / 52;
  183.         }
  184.         public double CalculateWeeklyPay(double modifiedSalary)
  185.         {
  186.             AnnualSalary = modifiedSalary;
  187.             return CalculateWeeklyPay();
  188.         }
  189.         public override string ToString() //displays information
  190.         {
  191.             string output;
  192.             output = "\n============ Employee Information ============";
  193.             output += "\n\t         Name:\t" + firstName + " " + lastName;
  194.             output += "\n\t       Gender:\t" + Gender;
  195.             output += "\n\t   Dependents:\t" + Dependents;
  196.             output += "\n\tAnnual Salary:\t" + AnnualSalary.ToString("C2");
  197.             output += "\n\t   Weekly Pay:\t" + CalculateWeeklyPay().ToString("C2");
  198.             return output;
  199.         }
  200.  
  201.        
  202.     }
  203. }
  204.  
  205.  
  206.  
  207.  
  208. using System;
  209. using System.Collections.Generic;
  210. using System.Linq;
  211. using System.Text;
  212. using System.Threading.Tasks;
  213.  
  214. //Programmer: Junkie
  215. //Date: 8/2/1014
  216. //Class: CIS 247 Week 4 Lab
  217. //About the class: The Benefit class sets the default values for health insurance, life insurance, and vacation days.
  218. //It also makes sure that the value inputted is not under the minimum or over the maximum.
  219. //Anything that is over or under will be displayed as the default value.
  220.  
  221. namespace CIS247A_Employee
  222. {
  223.     class Benefit
  224.     {
  225.         public Benefit()
  226.         {
  227.         }
  228.  
  229.         //default values
  230.         public const string DEFAULT_HEALTH_INSURANCE = "Blue Cross";
  231.         public const double MIN_LIFE_INSURANCE = 0;
  232.         public const double MAX_LIFE_INSURANCE = 1000000;
  233.         public const int MIN_VACATION = 0;
  234.         public const int MAX_VACATION = 45;
  235.  
  236.         //declaring the private variables for the Benefit class
  237.         private string healthInsuranceCompany;
  238.         private double lifeInsuranceAmount;
  239.         private int vacationDays;
  240.  
  241.         //We do this because the private variables cannot be used outside of this class
  242.         public Benefit(string healthInsuranceCompany, double lifeInsuranceAmount, int vacationDays)
  243.         {
  244.             HealthInsuranceCompany = healthInsuranceCompany;
  245.             LifeInsuranceAmount = lifeInsuranceAmount;
  246.             VacationDays = vacationDays;
  247.         }
  248.  
  249.         //If health insurance is empty then value will = Blue Cross (the dafault)
  250.         public string HealthInsuranceCompany
  251.         {
  252.             get { return healthInsuranceCompany; }
  253.             set
  254.             {
  255.                 if (String.IsNullOrEmpty(value))
  256.                     healthInsuranceCompany = DEFAULT_HEALTH_INSURANCE;
  257.                 else
  258.                     healthInsuranceCompany = value;
  259.             }
  260.         }
  261.  
  262.         //If life insurance is over or under then it will be displayed as one of the default values
  263.         public double LifeInsuranceAmount
  264.         {
  265.             get { return lifeInsuranceAmount; }
  266.             set
  267.             {
  268.                 if (value >= MIN_LIFE_INSURANCE && value <= MAX_LIFE_INSURANCE)
  269.                     lifeInsuranceAmount = value;
  270.                 else if (value < MIN_LIFE_INSURANCE)
  271.                     lifeInsuranceAmount = MIN_LIFE_INSURANCE;
  272.                 else
  273.                     LifeInsuranceAmount = MAX_LIFE_INSURANCE;
  274.             }
  275.         }
  276.  
  277.         //If vacation days is over or under then the value will be displayed as either maximum or minimum
  278.         public int VacationDays
  279.         {
  280.             get { return vacationDays; }
  281.             set
  282.             {
  283.                 if (value >= MIN_VACATION && value <= MAX_VACATION)
  284.                    vacationDays = value;
  285.                 else if (value < MIN_VACATION)
  286.                     vacationDays = MIN_VACATION;
  287.                 else
  288.                     vacationDays = MAX_VACATION;
  289.             }
  290.         }
  291.  
  292.         //this is how the benefit information will be displayed (called the the program class)
  293.         public override string ToString()
  294.         {
  295.             string output;
  296.             output = "\n============ Benefits Information ============";
  297.             output += "\n\t         Health Insurance Company:\t" + HealthInsuranceCompany;
  298.             output += "\n\t       Amount of Life Insurance:\t" + "$" + LifeInsuranceAmount;
  299.             output += "\n\t   Number of Vacation Days:\t" + VacationDays;
  300.             return output;
  301.         }
  302.     }
  303. }
  304.  
  305.  
  306.  
  307. using System;
  308. using System.Collections.Generic;
  309. using System.Linq;
  310. using System.Text;
  311.  
  312. namespace CIS247A_Employee
  313. {
  314.     public class InputUtilities
  315.     {
  316.        
  317.         public static string GetInput(string inputType)
  318.         {
  319.             string strInput = String.Empty;
  320.             Console.Write("Enter the " + inputType + ": ");
  321.             strInput = Console.ReadLine();
  322.  
  323.             return strInput;
  324.         }
  325.  
  326.         public static string GetStringInputValue(string inputType)
  327.         {
  328.             string value = String.Empty;
  329.             bool valid = false;
  330.             string inputString = String.Empty;
  331.             do
  332.             {
  333.                 inputString = GetInput(inputType);
  334.                 if (!String.IsNullOrEmpty(inputString))
  335.                 {
  336.                     value = inputString;
  337.                     valid = true;
  338.                 }
  339.                 else
  340.                 {
  341.                     value = "Invalid input";
  342.                     valid = false;
  343.                 }
  344.                 if (!valid)
  345.                     Console.WriteLine("Invalid " + inputType + " try again!");
  346.             } while (!valid);
  347.  
  348.             return value;
  349.         }
  350.         public static int GetIntegerInputValue(string inputType)
  351.         {
  352.             bool valid = false;
  353.             int value = 0;
  354.             string inputString = String.Empty;
  355.             do
  356.             {
  357.                 inputString = GetInput(inputType);
  358.                 if (!(String.IsNullOrEmpty(inputString)))
  359.                 {
  360.                     valid = Int32.TryParse(inputString, out value);
  361.                 }
  362.                 if (!valid)
  363.                     Console.WriteLine("Invalid " + inputType + " try again!");
  364.             } while (!valid);
  365.            
  366.             return value;
  367.         }
  368.         public static double GetDoubleInputValue(string inputType)
  369.         {
  370.             bool valid = false;
  371.             double value = 0;
  372.             string inputString = String.Empty;
  373.             do
  374.             {
  375.                 inputString = GetInput(inputType);
  376.                 if (!(String.IsNullOrEmpty(inputString)))
  377.                 {
  378.                     valid = Double.TryParse(inputString, out value);
  379.                 }
  380.                 if (!valid)
  381.                     Console.WriteLine("Invalid " + inputType + " try again!");
  382.             } while (!valid);
  383.  
  384.             return value;
  385.         }
  386.         public static char GetCharInputValue(string inputType)
  387.         {
  388.             bool valid = false;
  389.             char value = 'u';
  390.             string inputString = String.Empty;
  391.             do
  392.             {
  393.                 inputString = GetInput(inputType);
  394.                 if (!(String.IsNullOrEmpty(inputString)))
  395.                 {
  396.                     valid = Char.TryParse(inputString, out value);
  397.                 }
  398.                 if (!valid)
  399.                     Console.WriteLine("Invalid " + inputType + " try again!");
  400.             } while (!valid);
  401.  
  402.             return value;
  403.         }
  404.        
  405.     }
  406. }
  407.  
  408.  
  409.  
  410. using System;
  411. using System.Collections.Generic;
  412. using System.Linq;
  413. using System.Text;
  414.  
  415. /* Program Header
  416.  * Program Name: Basic User Interface
  417.  * Programer: Junkie
  418.  * CIS247, Week 3 Lab
  419.  * Program Description:
  420.  * This program gets employee information and benefits information.
  421.  * After data is entered the information will be displayed on screen.
  422.  * It also counts the number of employees and displays two default
  423.  * employees.
  424.  */
  425.  
  426. namespace CIS247A_Employee
  427. {
  428.     class Program
  429.     {
  430.         static void Main(string[] args)
  431.         {
  432.             double modifiedSalary;
  433.  
  434.             ApplicationUtilities.DisplayApplicationInformation();
  435.             ApplicationUtilities.DisplayDivider("Start Program");
  436.             ApplicationUtilities.DisplayDivider("Prompt for Employee information and create first employee");
  437.  
  438.             //Gets employee and benefits information.
  439.             Employee employee1 = new Employee();
  440.             Benefit benefit1 = new Benefit();
  441.             employee1.FirstName = InputUtilities.GetStringInputValue("First name");
  442.             employee1.LastName = InputUtilities.GetStringInputValue("Last name");
  443.             employee1.Gender = InputUtilities.GetCharInputValue("Gender");
  444.             employee1.Dependents = InputUtilities.GetIntegerInputValue("# Dependents");
  445.             employee1.AnnualSalary = InputUtilities.GetDoubleInputValue("Annual Salary");
  446.             benefit1.HealthInsuranceCompany = InputUtilities.GetStringInputValue("Name of health insurance company");
  447.             benefit1.LifeInsuranceAmount = InputUtilities.GetDoubleInputValue("Life insurance amount");
  448.             benefit1.VacationDays = InputUtilities.GetIntegerInputValue("Number of Vacation Days");
  449.             Console.WriteLine(employee1.ToString()); //displays employee information
  450.             Console.WriteLine(benefit1.ToString()); //displays benefit information
  451.             DisplayNumberEmployees();
  452.             ApplicationUtilities.PauseExecution();
  453.            
  454.             //Getting and displaying modified pay information
  455.             ApplicationUtilities.DisplayDivider("Get updated weeky pay");
  456.             modifiedSalary = InputUtilities.GetDoubleInputValue("Updated annual salary");
  457.             Console.WriteLine(employee1.EmployeeName + " modified Weekly pay: " + employee1.CalculateWeeklyPay(modifiedSalary).ToString("C2"));
  458.             ApplicationUtilities.PauseExecution();
  459.  
  460.             //creating the second employee
  461.             Employee employee2 = new Employee("Mary", "Noia", 'f', 3, 750000);
  462.             Console.WriteLine(employee2.ToString());
  463.             DisplayNumberEmployees();
  464.  
  465.             //creating the third employee
  466.             Employee employee3 = new Employee("Sue", "Smith", 'F', 15, 500000);
  467.             Console.WriteLine(employee3.ToString());
  468.  
  469.             DisplayNumberEmployees();
  470.             ApplicationUtilities.TerminateApplication();
  471.         }
  472.  
  473.         private static void DisplayNumberEmployees()
  474.         {
  475.              ApplicationUtilities.DisplayDivider("Number of Employee Object(s): " + Employee.NumberOfEmployees.ToString());
  476.         }
  477.        
  478.     }
  479. }
Add Comment
Please, Sign In to add comment