JunkieHF

Calculates Weekly Pay From Annual Salary C# Source

Jul 20th, 2014
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.99 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace Employee
  7. {
  8.     public class ApplicationUtilities
  9.     {
  10.         public static void DisplayApplicationInformation()
  11.         {
  12.             Console.WriteLine("Welcome to the Basic Employee Program");
  13.             Console.WriteLine("CIS247a, Week 2 Lab");
  14.             Console.WriteLine("Name: ");
  15.             Console.WriteLine("This program accepts user input as a string, then makes the \nappropriate data conversion and assigns the value to Employee objects");
  16.             Console.WriteLine();
  17.         }
  18.         public static void DisplayDivider(string outputTitle)
  19.         {
  20.             Console.WriteLine("\n********* " + outputTitle + " *********\n");
  21.         }
  22.         public static void TerminateApplication()
  23.         {
  24.             DisplayDivider("Program Termination");
  25.             Console.Write("Thank you.  Press any key to terminate the program...");
  26.             Console.ReadLine();
  27.         }
  28.         public static void PauseExecution()
  29.         {
  30.             Console.Write("\nProgram paused, press any key to continue...");
  31.             Console.ReadLine();
  32.             Console.WriteLine();
  33.         }
  34.     }
  35. }
  36.  
  37. using System;
  38. using System.Collections.Generic;
  39. using System.Linq;
  40. using System.Text;
  41. using System.Threading.Tasks;
  42.  
  43. namespace
  44.  
  45.  
  46.  
  47. Employee
  48. {
  49.     class Employee
  50.     {
  51.         public string firstName  = "not given";
  52.         public string lastName = "not given";
  53.         public char gender = 'U';
  54.         public int dependants = 0;
  55.         public double annualSalary = 20000;
  56.         public double weeklyPay = 0;
  57.  
  58.         public Employee()
  59.         {
  60.         }
  61.  
  62.  public Employee(string firstName, string lastName, char gender, int dependants, double annualSalary, double weeklyPay)
  63.         {
  64. this.firstName = firstName;
  65. this.lastName = lastName;
  66. this.gender = gender;
  67. this.dependants = dependants;
  68. this.annualSalary = annualSalary;
  69. this.weeklyPay = CalculateWeeklyPay();
  70.         }
  71.  public  double CalculateWeeklyPay()
  72.         {
  73.  double wPay;
  74. wPay = annualSalary / 52; //weekly pay is annual salary divided by 52
  75. return wPay;
  76.  }
  77.  
  78.  public override string ToString()
  79.  {
  80.      string output;
  81.      output =
  82.      "======Employee Information=========\n" +  //This will output once the information is given
  83.     " Name: " + firstName + " " + lastName + "\n" +
  84.     " Gender: " + gender + "\n" +
  85.     " Depednants: " + dependants + "\n" +
  86.     "Annual Salary: " + annualSalary + "\n" +
  87.      " Weekly Pay: " + CalculateWeeklyPay();
  88.      return output;
  89.  
  90.  
  91.  }
  92.     }
  93. }
  94.  
  95. using System;
  96. using System.Collections.Generic;
  97. using System.Linq;
  98. using System.Text;
  99.  
  100. namespace Employee
  101. {
  102.     public class InputUtilities
  103.     {
  104.         public static string GetInput(string inputType)
  105.         {
  106.             string strInput = String.Empty;
  107.             Console.Write("Enter your " + inputType + ": ");
  108.             strInput = Console.ReadLine();
  109.  
  110.             return strInput;
  111.         }
  112.         public static string getStringInputValue(string inputType)
  113.         {
  114.             string value = String.Empty;
  115.             bool valid = false;
  116.             string inputString = String.Empty;
  117.             do
  118.             {
  119.                 inputString = GetInput(inputType);
  120.                 if (!String.IsNullOrEmpty(inputString))
  121.                 {
  122.                     value = inputString;
  123.                     valid = true;
  124.                 }
  125.                 else
  126.                 {
  127.                     value = "Invalid input";
  128.                     valid = false;
  129.                 }
  130.                 if (!valid)
  131.                     Console.WriteLine("Invalid " + inputType + " try again!");
  132.             } while (!valid);
  133.  
  134.             return value;
  135.         }
  136.         public static int getIntegerInputValue(string inputType)
  137.         {
  138.             bool valid = false;
  139.             int value = 0;
  140.             string inputString = String.Empty;
  141.             do
  142.             {
  143.                 inputString = GetInput(inputType);
  144.                 if (!(String.IsNullOrEmpty(inputString)))
  145.                 {
  146.                     valid = Int32.TryParse(inputString, out value);
  147.                 }
  148.                 if (!valid)
  149.                     Console.WriteLine("Invalid " + inputType + " try again!");
  150.             } while (!valid);
  151.            
  152.             return value;
  153.         }
  154.         public static double getDoubleInputValue(string inputType)
  155.         {
  156.             bool valid = false;
  157.             double value = 0;
  158.             string inputString = String.Empty;
  159.             do
  160.             {
  161.                 inputString = GetInput(inputType);
  162.                 if (!(String.IsNullOrEmpty(inputString)))
  163.                 {
  164.                     valid = Double.TryParse(inputString, out value);
  165.                 }
  166.                 if (!valid)
  167.                     Console.WriteLine("Invalid " + inputType + " try again!");
  168.             } while (!valid);
  169.  
  170.             return value;
  171.         }
  172.         public static char getCharInputValue(string inputType)
  173.         {
  174.             bool valid = false;
  175.             char value = 'u';
  176.             string inputString = String.Empty;
  177.             do
  178.             {
  179.                 inputString = GetInput(inputType);
  180.                 if (!(String.IsNullOrEmpty(inputString)))
  181.                 {
  182.                     valid = Char.TryParse(inputString, out value);
  183.                 }
  184.                 if (!valid)
  185.                     Console.WriteLine("Invalid " + inputType + " try again!");
  186.             } while (!valid);
  187.  
  188.             return value;
  189.         }
  190.        
  191.     }
  192. }
  193.  
  194. using System;
  195. using System.Collections.Generic;
  196. using System.Linq;
  197. using System.Text;
  198. using System.Threading.Tasks;
  199.  
  200. namespace Employee
  201. {
  202.     public class Program
  203.     {
  204.         public static void Main(string[] args)
  205.         {
  206.  
  207.             ApplicationUtilities.DisplayApplicationInformation(); //Displays Program Information
  208.             ApplicationUtilities.DisplayDivider("START PROGRAM");
  209.             ApplicationUtilities.DisplayDivider("PROMPT FOR EMPLOYEE INFORMATION AND CREATE FIRST EMPLOYEE");
  210.  
  211.             Employee emp1 = new Employee(); //Information for Employee #1
  212.             emp1.firstName =
  213.                 InputUtilities.getStringInputValue("First name");
  214.             emp1.lastName =
  215.                 InputUtilities.getStringInputValue("last name");
  216.             emp1.gender =
  217.                 InputUtilities.getCharInputValue("Gender");
  218.             emp1.dependants =
  219.                 InputUtilities.getIntegerInputValue("# of dependants");
  220.             emp1.annualSalary =
  221.                 InputUtilities.getDoubleInputValue("Annual salary");
  222.             Console.WriteLine(emp1);
  223.            
  224.             ApplicationUtilities.PauseExecution(); //Pause
  225.  
  226.             Employee emp2 = new Employee("John", "Smith", 'm', 2, 50000, 50000/52);
  227.             Console.WriteLine(emp2);
  228.  
  229.             ApplicationUtilities.TerminateApplication(); //Closes the Application
  230.  
  231.  
  232.         }
  233.     }
  234. }
Add Comment
Please, Sign In to add comment