我正在尝试编写一个简单的程序来计算员工的netpay。据我所知,我的代码是可靠的,除了我的方法调用DisplayOutput(); 我理解错误意味着什么,但我不明白如何修复它。
这是我的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Project02CoddR
{
class NetPayApp
{
static void Main(string[] args)
{
Console.BackgroundColor = ConsoleColor.White;
Console.ForegroundColor = ConsoleColor.Black;
Console.Clear();
DisplayTitle();
InputData();
DisplayOutput();
TerminateProgram();
}
public static void DisplayTitle()
{
Console.WriteLine();
Console.Write("\tProject 02 - Net Pay Calculator - ");
Console.WriteLine();
DrawLine();
}
public static void InputData()
{
Console.WriteLine();
Console.Write("Please enter the number of hours worked this week: ");
int hoursWorked = Convert.ToInt32(Console.ReadLine());
Console.WriteLine();
Console.Write("Please enter your hourly rate of pay <e.g. 9.35>: ");
double payRate = Convert.ToDouble(Console.ReadLine());
Console.WriteLine();
Console.Write("Please enter your number of dependants: ");
int dependants = Convert.ToInt32(Console.ReadLine());
Console.WriteLine();
Console.Write("\n\tAre you a salesperson? <Y or N>: ");
string aValue = Console.ReadLine();
}
public static int InputSales(string aValue)
{
int sales = -1;
if (aValue == "Y" || aValue == "y" || aValue == "Yes" || aValue == "yes")
{
Console.Write("Please enter your sales amount for this period: ");
sales = Convert.ToInt32(Console.ReadLine());
}
else if (aValue == "N" || aValue == "n" || aValue == "No" || aValue == "no")
{
sales = -1;
}
return sales;
}
public static double CalculatePay(int hoursWorked, double payRate, int sales)
{
double grossPay = hoursWorked * payRate;
if (sales >= 0)
{
grossPay = grossPay +(.02*sales);
}
else if (hoursWorked > 40)
{
grossPay = grossPay + (.5*payRate) * (hoursWorked-40);
}
return grossPay;
}
public static double CalculateTax(int dependants, double grossPay)
{
int cutOff = 100 + (100 * dependants);
double taxes;
if (grossPay <= cutOff)
{
taxes = .15 * grossPay;
}
else
{
taxes = .15 * cutOff + .25*(grossPay-cutOff);
}
return taxes;
}
public static void DisplayOutput(double grossPay, double taxes)
{
double netPay = grossPay - taxes;
Console.WriteLine();
Console.WriteLine("Gross Pay: ".PadLeft(30, ' ') + grossPay);
Console.WriteLine("Taxes: ".PadLeft(30, ' ') + taxes);
Console.WriteLine("Net Pay: ".PadLeft(30, ' ') + netPay);
Console.WriteLine();
DrawLine();
}
public static void DrawLine()
{
Console.Write("______________________________________________");
}
public static void TerminateProgram()
{
Console.Write("Press any key to terminate the program...");
Console.Read();
}
}
}
答案 0 :(得分:0)
DisplayOutput需要显示传递给它的值;例如:
static void Main(string[] args)
{
Console.BackgroundColor = ConsoleColor.White;
Console.ForegroundColor = ConsoleColor.Black;
Console.Clear();
DisplayTitle();
InputData();
DisplayOutput(CalculatePay(40, 50, 60), CalculateTax(4, CalculatePay(40, 50, 60)));
TerminateProgram();
}