2013-10-15 53 views
0

我想編寫一個簡單的程序來計算員工的netpay。據我所知,我的代碼是堅實的,除了我的方法調用DisplayOutput(); 我明白錯誤意味着什麼,但我不明白如何解決它的編譯問題。方法'DisplayOutput'沒有超載需要0個參數

這裏是我的代碼:

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

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(); 
    } 
相關問題