JunkieHF

Weekly Pay Calculator C# Source

Jul 20th, 2014
507
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.28 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Weekly_Pay_Calculator
  8. {
  9.     class ApplicationUtilities
  10.     {
  11.         //Displays information
  12.             public static void DisplayApplicationInformation()
  13.             {
  14.                 Console.WriteLine("Welcome to the Weekly Pay Calculator! [PRESS ENTER]");
  15.                 Console.ReadLine();
  16.                 Console.WriteLine("Programmer: Junkie [PRESS ENTER]");
  17.                 Console.ReadLine();
  18.                 Console.WriteLine("This program gets hours worked from user and calculates weekly pay. The employee receives $7.50 per hour for the first 40 hours and $11.25 per hour for each additional hour.  ");
  19.             }
  20.             //Divider
  21.             internal static void DisplayDivider(string outputTitle)
  22.             {
  23.                 Console.WriteLine("****************" + outputTitle + "****************");
  24.             }
  25.  
  26.             //The program ends here
  27.             internal static void TerminateApplication()
  28.             {
  29.                 Console.WriteLine("Thank you for using the Weekly Pay Calculator. Press the ENTER key to exit.");
  30.                 Console.ReadLine();
  31.             }
  32.         }
  33.     }
  34.    
  35. //New Class Starts Here
  36. using System;
  37. using System.Collections.Generic;
  38. using System.Linq;
  39. using System.Text;
  40. using System.Threading.Tasks;
  41.  
  42. namespace Weekly_Pay_Calculator
  43. {
  44.     class InputUtilities
  45.     {
  46.         public static string GetInput(string inputType) //declaring GetInput
  47.         {
  48.             string strInput = String.Empty;
  49.             Console.Write("Enter your " + inputType + ": ");
  50.             strInput = Console.ReadLine();
  51.  
  52.             return strInput;
  53.         }
  54.         public static double getDoubleInputValue(string inputType) //makes sure user inputs a double
  55.         {
  56.             bool valid = false;
  57.             double value = 0;
  58.             string inputString = String.Empty;
  59.             do
  60.             {
  61.                 inputString = GetInput(inputType);
  62.                 if (!(String.IsNullOrEmpty(inputString)))
  63.                 {
  64.                     valid = Double.TryParse(inputString, out value);
  65.                 }
  66.                 if (!valid)
  67.                     Console.WriteLine("Invalid " + inputType + " try again!"); //if not a double
  68.             } while (!valid);
  69.  
  70.             return value;
  71.         }
  72.     }
  73. }
  74.  
  75. //New Class Starts Here
  76. using System;
  77. using System.Collections.Generic;
  78. using System.Linq;
  79. using System.Text;
  80. using System.Threading.Tasks;
  81.  
  82. namespace Weekly_Pay_Calculator
  83. {
  84.     class Program
  85.     {
  86.         static void Main(string[] args)
  87.         {
  88.             ApplicationUtilities.DisplayApplicationInformation(); //Displays Program Information
  89.             ApplicationUtilities.DisplayDivider("START PROGRAM");
  90.             Console.WriteLine("Press [ENTER] to Begin");
  91.             Console.ReadLine();
  92.             ApplicationUtilities.DisplayDivider("PROMPT FOR Hours Worked And Overtime"); //in the below lines we are asking the user how many hours they have worked
  93.  
  94.             Console.WriteLine("How many regular hours did you work?");
  95.             double hoursWorked = InputUtilities.getDoubleInputValue("Regular Time Worked");
  96.             Console.WriteLine("How many overtime hours did you work?");
  97.             double overtime = InputUtilities.getDoubleInputValue("Overtime worked");
  98.             double weeklyPay = hoursWorked * 7.50;
  99.             double overtimePay = overtime * 11.25;
  100.             double totalPay = weeklyPay + overtimePay;
  101.             Console.WriteLine("You have earned the following amount for your regular hours: " + weeklyPay); //displays amount earned for reg hours
  102.             Console.WriteLine("Press ENTER");
  103.             Console.ReadLine();
  104.             Console.WriteLine("You have earned the following amount in overtime: " + overtimePay); //overtime earnings
  105.             Console.WriteLine("Press Enter");
  106.             Console.ReadLine();
  107.             Console.WriteLine("Your total earnings for this week is: " + totalPay); //total earnings
  108.             Console.WriteLine("Press Enter");
  109.             Console.ReadLine();
  110.            
  111.             ApplicationUtilities.TerminateApplication(); //Exits the application
  112.         }    
  113.         }
  114.     }
Add Comment
Please, Sign In to add comment