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 CIS247A_Employee
- {
- public class ApplicationUtilities
- {
- //Displays information about the program
- public static void DisplayApplicationInformation()
- {
- Console.WriteLine("Overloaded Methods and Statice Members");
- Console.WriteLine("CIS247a, Week 4 Lab");
- Console.WriteLine("Name: Junkie");
- 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");
- }
- //Closes the application
- public static void TerminateApplication()
- {
- DisplayDivider("Program Termination");
- Console.Write("Thank you. Press any key to terminate the program...");
- Console.ReadLine();
- }
- //Pauses the application
- 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;
- /******************************************************************
- * Course: CIS247A
- * Week: 4
- * Programmer: Junkie
- * Date: 8/2/2014
- *
- * Class Name: Employee
- * Class Description:
- * The employee class stores the first and last name, annual salary,
- * gender, and # of dependents. It makes sure that none of the values goes
- * over the the maximum amount or under the minimum amount. It also calculates
- * weekly pay and shows how the information will be displayed.
- ***********************************************************************/
- namespace CIS247A_Employee
- {
- public class Employee
- {
- public const double MIN_SALARY = 20000;
- public const double MAX_SALARY = 100000;
- public const int MIN_DEPENDENTS = 0;
- public const int MAX_DEPENDENTS = 10;
- public const string DEFAULT_NAME = "not given";
- private string firstName;
- private string lastName;
- private double annualSalary;
- private char gender;
- private int dependents;
- //since static, there will be only one copy of the number created variable
- private static int numberEmployees = 0;
- public Employee()
- {
- FirstName = DEFAULT_NAME;
- LastName = DEFAULT_NAME;
- AnnualSalary = MIN_SALARY;
- Dependents = MIN_DEPENDENTS;
- //make sure to increment number of employees each time a instance is created
- numberEmployees += 1;
- }
- public Employee(string firstname, string lastname, char gender, int dependents, double salary)
- {
- FirstName = firstname;
- LastName = lastname;
- AnnualSalary = salary;
- Gender = gender;
- Dependents = dependents;
- //make sure to increment number of employees each time a instance is created
- numberEmployees += 1;
- }
- public static int NumberOfEmployees
- {
- get { return numberEmployees; }
- }
- public string FirstName
- {
- get { return firstName; }
- set
- {
- if (String.IsNullOrEmpty(value)) //if string is empty then firstName = DEFAULT_NAME
- firstName = DEFAULT_NAME;
- else
- firstName = value; //if string is not empty then name = input value
- }
- }
- public string LastName //last name is checked the same as first name
- {
- get { return lastName; }
- set
- {
- if (String.IsNullOrEmpty(value))
- lastName = DEFAULT_NAME;
- else
- lastName = value;
- }
- }
- //if gender does not equal F or M then gender will be U. If gender = M or F then gender = input value
- public char Gender
- {
- get { return gender; }
- set
- {
- char input;
- input = Char.ToUpper(value);
- if (input == 'F' || input == 'M')
- gender = input;
- else
- gender = 'U';
- }
- }
- //if dependents is less than or greater than max_dependents (10) then dependents = max
- // if dependents is less than min_dependents(0) then dependents = minimum
- // else dependents = input value
- public int Dependents
- {
- get { return dependents; }
- set
- {
- if (value >= MIN_DEPENDENTS && value <= MAX_DEPENDENTS)
- dependents = value;
- else if (value < MIN_DEPENDENTS)
- dependents = MIN_DEPENDENTS;
- else
- dependents = MAX_DEPENDENTS;
- }
- }
- // if Annual Salary is less than minimum salary then annual salary is the minimum amount
- // If annual salary is more than maximum salary then the annual salary is the maximum amount
- // if annual salary is not less than minimum salary and not greater than maximum salary then annual salary = input value
- public double AnnualSalary
- {
- get { return annualSalary; }
- set
- {
- if (value < MIN_SALARY)
- annualSalary = MIN_SALARY;
- else if (value > MAX_SALARY)
- annualSalary = MAX_SALARY;
- else
- annualSalary = value;
- }
- }
- public string EmployeeName
- {
- get { return FirstName + " " + LastName; }
- }
- public double CalculateWeeklyPay()
- {
- return AnnualSalary / 52;
- }
- public double CalculateWeeklyPay(double modifiedSalary)
- {
- AnnualSalary = modifiedSalary;
- return CalculateWeeklyPay();
- }
- public override string ToString() //displays information
- {
- string output;
- output = "\n============ Employee Information ============";
- output += "\n\t Name:\t" + firstName + " " + lastName;
- output += "\n\t Gender:\t" + Gender;
- output += "\n\t Dependents:\t" + Dependents;
- output += "\n\tAnnual Salary:\t" + AnnualSalary.ToString("C2");
- output += "\n\t Weekly Pay:\t" + CalculateWeeklyPay().ToString("C2");
- return output;
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- //Programmer: Junkie
- //Date: 8/2/1014
- //Class: CIS 247 Week 4 Lab
- //About the class: The Benefit class sets the default values for health insurance, life insurance, and vacation days.
- //It also makes sure that the value inputted is not under the minimum or over the maximum.
- //Anything that is over or under will be displayed as the default value.
- namespace CIS247A_Employee
- {
- class Benefit
- {
- public Benefit()
- {
- }
- //default values
- public const string DEFAULT_HEALTH_INSURANCE = "Blue Cross";
- public const double MIN_LIFE_INSURANCE = 0;
- public const double MAX_LIFE_INSURANCE = 1000000;
- public const int MIN_VACATION = 0;
- public const int MAX_VACATION = 45;
- //declaring the private variables for the Benefit class
- private string healthInsuranceCompany;
- private double lifeInsuranceAmount;
- private int vacationDays;
- //We do this because the private variables cannot be used outside of this class
- public Benefit(string healthInsuranceCompany, double lifeInsuranceAmount, int vacationDays)
- {
- HealthInsuranceCompany = healthInsuranceCompany;
- LifeInsuranceAmount = lifeInsuranceAmount;
- VacationDays = vacationDays;
- }
- //If health insurance is empty then value will = Blue Cross (the dafault)
- public string HealthInsuranceCompany
- {
- get { return healthInsuranceCompany; }
- set
- {
- if (String.IsNullOrEmpty(value))
- healthInsuranceCompany = DEFAULT_HEALTH_INSURANCE;
- else
- healthInsuranceCompany = value;
- }
- }
- //If life insurance is over or under then it will be displayed as one of the default values
- public double LifeInsuranceAmount
- {
- get { return lifeInsuranceAmount; }
- set
- {
- if (value >= MIN_LIFE_INSURANCE && value <= MAX_LIFE_INSURANCE)
- lifeInsuranceAmount = value;
- else if (value < MIN_LIFE_INSURANCE)
- lifeInsuranceAmount = MIN_LIFE_INSURANCE;
- else
- LifeInsuranceAmount = MAX_LIFE_INSURANCE;
- }
- }
- //If vacation days is over or under then the value will be displayed as either maximum or minimum
- public int VacationDays
- {
- get { return vacationDays; }
- set
- {
- if (value >= MIN_VACATION && value <= MAX_VACATION)
- vacationDays = value;
- else if (value < MIN_VACATION)
- vacationDays = MIN_VACATION;
- else
- vacationDays = MAX_VACATION;
- }
- }
- //this is how the benefit information will be displayed (called the the program class)
- public override string ToString()
- {
- string output;
- output = "\n============ Benefits Information ============";
- output += "\n\t Health Insurance Company:\t" + HealthInsuranceCompany;
- output += "\n\t Amount of Life Insurance:\t" + "$" + LifeInsuranceAmount;
- output += "\n\t Number of Vacation Days:\t" + VacationDays;
- return output;
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace CIS247A_Employee
- {
- public class InputUtilities
- {
- public static string GetInput(string inputType)
- {
- string strInput = String.Empty;
- Console.Write("Enter the " + 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;
- /* Program Header
- * Program Name: Basic User Interface
- * Programer: Junkie
- * CIS247, Week 3 Lab
- * Program Description:
- * This program gets employee information and benefits information.
- * After data is entered the information will be displayed on screen.
- * It also counts the number of employees and displays two default
- * employees.
- */
- namespace CIS247A_Employee
- {
- class Program
- {
- static void Main(string[] args)
- {
- double modifiedSalary;
- ApplicationUtilities.DisplayApplicationInformation();
- ApplicationUtilities.DisplayDivider("Start Program");
- ApplicationUtilities.DisplayDivider("Prompt for Employee information and create first employee");
- //Gets employee and benefits information.
- Employee employee1 = new Employee();
- Benefit benefit1 = new Benefit();
- employee1.FirstName = InputUtilities.GetStringInputValue("First name");
- employee1.LastName = InputUtilities.GetStringInputValue("Last name");
- employee1.Gender = InputUtilities.GetCharInputValue("Gender");
- employee1.Dependents = InputUtilities.GetIntegerInputValue("# Dependents");
- employee1.AnnualSalary = InputUtilities.GetDoubleInputValue("Annual Salary");
- benefit1.HealthInsuranceCompany = InputUtilities.GetStringInputValue("Name of health insurance company");
- benefit1.LifeInsuranceAmount = InputUtilities.GetDoubleInputValue("Life insurance amount");
- benefit1.VacationDays = InputUtilities.GetIntegerInputValue("Number of Vacation Days");
- Console.WriteLine(employee1.ToString()); //displays employee information
- Console.WriteLine(benefit1.ToString()); //displays benefit information
- DisplayNumberEmployees();
- ApplicationUtilities.PauseExecution();
- //Getting and displaying modified pay information
- ApplicationUtilities.DisplayDivider("Get updated weeky pay");
- modifiedSalary = InputUtilities.GetDoubleInputValue("Updated annual salary");
- Console.WriteLine(employee1.EmployeeName + " modified Weekly pay: " + employee1.CalculateWeeklyPay(modifiedSalary).ToString("C2"));
- ApplicationUtilities.PauseExecution();
- //creating the second employee
- Employee employee2 = new Employee("Mary", "Noia", 'f', 3, 750000);
- Console.WriteLine(employee2.ToString());
- DisplayNumberEmployees();
- //creating the third employee
- Employee employee3 = new Employee("Sue", "Smith", 'F', 15, 500000);
- Console.WriteLine(employee3.ToString());
- DisplayNumberEmployees();
- ApplicationUtilities.TerminateApplication();
- }
- private static void DisplayNumberEmployees()
- {
- ApplicationUtilities.DisplayDivider("Number of Employee Object(s): " + Employee.NumberOfEmployees.ToString());
- }
- }
- }
Add Comment
Please, Sign In to add comment