can any one help me Here is the C# adaption:
using System;
public class Payroll {
public static void Main(string[] args) {
// Prompt the user to input stuff
Console.WriteLine("Enter an employee's name: ");
string empName = Console.ReadLine();
Console.WriteLine("Enter the number of hours worked in a week: ");
double hoursWorked = Convert.ToDouble( Console.ReadLine() );
Console.WriteLine("Enter the hourly pay rate: ");
double payRate = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter Federal tax withholding rate: ");
double federalTaxRate = Convert.ToDouble(Console.ReadLine());
federalTaxRate = federalTaxRate / 100;
Console.WriteLine("Enter state tax withholding rate: ");
double stateTaxRate = Convert.ToDouble( Console.ReadLine() );
stateTaxRate = stateTaxRate / 100;
// Calculate stuff
double grossPay = hoursWorked * payRate;
double federalWithholding = grossPay * federalTaxRate;
double stateWithholding = grossPay * stateTaxRate;
double totalDeductions = federalWithholding + stateWithholding;
double netPay = grossPay - totalDeductions;
//Here is where the output (stuff) should be a payroll statement
Console.WriteLine("Employee Name: " + empName);
Console.WriteLine("Hours worked: " + hoursWorked);
Console.WriteLine("Pay Rate: " + payRate);
Console.WriteLine("Gross Pay: " + grossPay);
Console.WriteLine("Deductions... ");
Console.WriteLine("Federal Withholding (" + federalTaxRate + "%) : " + federalWithholding);
Console.WriteLine("State Withholding (" + stateTaxRate + "%) : " + stateWithholding);
Console.WriteLine("Total Deduction: " + totalDeductions);
Console.WriteLine("Net Pay: " + netPay);
Console.WriteLine("Press Enter key to exit");
Console.ReadLine();
}
} here is my answer in java... c sharp is relatively close to java no?
import java.util.Scanner; // Scanner is in java.util
public class Payroll {
public static void main(String args[]) {
// Create a Scanner
Scanner scanner = new Scanner(System.in);
// Prompt the user to input stuff
System.out.print("Enter an employee's name: ");
String empName = scanner.next();
System.out.print("Enter the number of hours worked in a week: ");
double hoursWorked = scanner.nextDouble();
System.out.print("Enter the hourly pay rate: ");
double payRate = scanner.nextDouble();
System.out.print("Enter Federal tax withholding rate: ");
double federalTaxRate = scanner.nextDouble();
federalTaxRate = federalTaxRate / 100;
System.out.print("Enter state tax withholding rate: ");
double stateTaxRate = scanner.nextDouble();
stateTaxRate = stateTaxRate / 100;
// Calculate stuff
double grossPay = hoursWorked * payRate;
double federalWithholding = grossPay * federalTaxRate;
double stateWithholding = grossPay * stateTaxRate;
double totalDeductions = federalWithholding + stateWithholding;
double netPay = grossPay - totalDeductions;
//Here is where the output (stuff) should be a payroll statement
System.out.println("Employee Name: " + empName);
System.out.println("Hours worked: " + hoursWorked);
System.out.println("Pay Rate: " + payRate);
System.out.println("Gross Pay: " + grossPay);
System.out.println("Deductions: ");
System.out.println("Federal Withholding (" + federalTaxRate + "%) : " + federalWithholding);
System.out.println("State Withholding (" + stateTaxRate + "%) : " + stateWithholding);
System.out.println("Total Deduction: " + totalDeductions);
System.out.println("Net Pay: " + netPay);
}
} |