Instead of following the course of action I expected, the program appears to be asking questions in accordance to the order the variables are in. The gross and net incomes are also not working but I am not worried about that at the moment. One problem at a time. Right now I just want it to scroll through the questions correctly.
Here is the code for the first class
using System;
namespace Exercise5_4
{
public class PayrollApp
{
public static void Main(string[] args)
{
String employeeType = SalaryOrHourly();
string employeeName = AskForEmployeeName();
double salary = AskForSalary();
double hoursWorked = AskForHoursWorked();
double hourlyWage = AskForHourlyWage();
double overTimeWorked = OverTimeWorked(hoursWorked);
double overTimeWage = OverTimeWage(hourlyWage);
double grossPay = GrossPay(salary);
if (employeeType == "Salary")
{
Employee salariedEmployeeObject = new Employee();
salariedEmployeeObject.EmployeeName = AskForEmployeeName();
salariedEmployeeObject.Salary = AskForSalary();
salariedEmployeeObject.GrossPay = GrossPay(salary);
salariedEmployeeObject.NetPay = NetPay(grossPay);
salariedEmployeeObject.ToString();
}
else if (employeeType == "Hourly")
{
Employee hourlyEmployeeObject = new Employee();
hourlyEmployeeObject.EmployeeName = AskForEmployeeName();
hourlyEmployeeObject.HourlyRate = AskForHourlyWage();
hourlyEmployeeObject.HoursWorked = AskForHoursWorked();
hourlyEmployeeObject.OverTimeWorked = OverTimeWorked(
hoursWorked);
hourlyEmployeeObject.OverTimeRate = OverTimeWage(hourlyWage);
hourlyEmployeeObject.GrossPay = GrossPay(hourlyWage,
hoursWorked, overTimeWorked, overTimeWage);
hourlyEmployeeObject.NetPay = NetPay(grossPay);
hourlyEmployeeObject.ToString();
}
}
//classs method to request employee name
public static String AskForEmployeeName()
{
String employeeName;
Console.WriteLine("Enter Employee Name: ");
employeeName = Console.ReadLine();
return employeeName;
}
//class method to determin if employee is salary or hourly
public static String SalaryOrHourly()
{
Console.WriteLine("Salary or Hourly (case sensitive): ");
String employeeType = Console.ReadLine();
return employeeType;
}
//class method to request salary
public static double AskForSalary()
{
Console.WriteLine("Enter salary: ");
double salary = double.Parse(Console.ReadLine());
return salary;
}
//class method to request hourly wage
public static double AskForHourlyWage()
{
Console.WriteLine("Enter Hourly Wage: ");
double hourlyWage = double.Parse(Console.ReadLine());
return hourlyWage;
}
//class method to request hours worked
public static double AskForHoursWorked()
{
Console.WriteLine("Enter hours worked: ");
double hoursWorked = double.Parse(Console.ReadLine());
return hoursWorked;
}
//class method to calculate overtime worked
public static double OverTimeWorked(double hoursWorked)
{
double overTimeWorked;
if (hoursWorked <= 40)
{
overTimeWorked = 0;
return overTimeWorked;
}
else
{
overTimeWorked = hoursWorked - 40;
return overTimeWorked;
}
}
//class method to calculate overtime rate
public static double OverTimeWage(double hourlywage)
{
double overTimeWage = 1.5 * hourlywage;
return overTimeWage;
}
//one of the overloaded mutator methods for grossPay datafield
public static double GrossPay(double salary)
{
double grossPay = salary;
return grossPay;
}
//one of the overloaded mutator methods for grossPay datafield
public static double GrossPay(double hourlyRate, double hoursWorked,
double overTimeWorked, double overTimeRate)
{
double grossPay = (hourlyRate * hoursWorked) +
(overTimeRate * overTimeWorked);
return grossPay;
}
//mutator method for netPay datafield
public static double NetPay(double grossPay)
{
const double FEDERAL_TAX_RATE = 0.18,
SOCIAL_SECURITY_TAX_RATE = 0.06,
RETIREMENT_FUND = 0.10;
double federalTaxOwed = grossPay * FEDERAL_TAX_RATE,
socialSecurityTaxOwed =
grossPay * SOCIAL_SECURITY_TAX_RATE,
retirementContribution = grossPay * RETIREMENT_FUND;
double netPay =
grossPay - federalTaxOwed - socialSecurityTaxOwed -
retirementContribution;
return netPay;
}
}
}
and here is the code for the second class
using System;
namespace Payroll
{
public class Employee
{
//declare variables
private String employeeName;
private double salary;
private double hourlyRate,
hoursWorked,
overTimeWorked,
overTimeRate,
grossPay,
netPay;
//property of the employeeName datafield
public String EmployeeName
{
get
{
return employeeName;
}
set
{
employeeName = value;
}
}
//property of the salary datafield
public double Salary
{
get
{
return salary;
}
set
{
salary = value;
}
}
//property of hourlyRate datafield
public double HourlyRate
{
get
{
return hourlyRate;
}
set
{
hourlyRate = value;
}
}
//property of the hoursWorked datafield
public double HoursWorked
{
get
{
return hoursWorked;
}
set
{
hoursWorked = value;
}
}
//property of the overTimeWorked datafield
public double OverTimeWorked
{
get
{
return overTimeWorked;
}
set
{
overTimeWorked = value;
}
}
//property of the overTimeRate datafield
public double OverTimeRate
{
get
{
return overTimeRate;
}
set
{
overTimeRate = value;
}
}
//property of the overTimeRate datafield
public double GrossPay
{
get
{
return grossPay;
}
set
{
grossPay = value;
}
}
public double NetPay
{
get
{
return netPay;
}
set
{
netPay = value;
}
}
//create default constructor
public Employee()
{
}
//create constructor for salaried employees
public Employee(String empName, double sal)
{
employeeName = empName;
salary = sal;
}
//create constructor for hourly employees
public Employee(String empName, double hrlyRate, double hrsWorked)
{
employeeName = empName;
hourlyRate = hrlyRate;
hoursWorked = hrsWorked;
}
//edit ToString() method
public override string ToString()
{
return "Gross Pay: " + grossPay.ToString("C") +
"Net Pay: " + netPay.ToString("C");
}
}
}

New Topic/Question
Reply



MultiQuote





|