-4

メソッドのオーバーロードなし。私は何を間違っていますか? 私の頭はすでに痛いです:)

//this is the first class named Employee
namespace lala
{
public class Employee
{
    public static double GrossPay(double WeeklySales) //grosspay
    {

        return WeeklySales * .07;
    }

    public static double FedTaxPaid(double GrossPay)
    {
        return GrossPay * .18;
    }

    public static double RetirementPaid(double GrossPay)
    {
        return GrossPay * .1;
    }

    public static double SocSecPaid(double GrossPay)
    {
        return GrossPay * .06;
    }

    public static double TotalDeductions(double SocSecPaid, double RetirementPaid, double FedTaxPaid)
    {
        return SocSecPaid + RetirementPaid + FedTaxPaid;
    }

    public static double TakeHomePay(double GrossPay, double TotalDeductions)
    {
        return GrossPay - TotalDeductions;
    }
}

}

これは EmployeeApp という名前の 2 番目のクラスです。これは、プログラムが機能しない理由がわからない場所です。

namespace lala
{
public class EmployeeApp
{
    public static string name;
    public static double WeeklySales;

    public static void Main()
    {
        Employee yuki = new Employee();

        GetInfo();

        Console.WriteLine();

        Console.WriteLine("Name: {0}", name);

        Console.WriteLine();

        Console.WriteLine("Gross Pay            : {0}", yuki.GrossPay());

        Console.WriteLine("Federal Tax Paid     : {0}", yuki.FedTaxPaid());
        Console.WriteLine("Social Security Paid : {0}", yuki.SocSecPaid());
        Console.WriteLine("Retirement Paid      : {0}", yuki.RetirementPaid());
        Console.WriteLine("Total Deductions     : {0}", yuki.TotalDeductions());

        Console.WriteLine();

        Console.WriteLine("Take-Home Pay        : {0}", yuki.TakeHomePay());

        Console.ReadKey();
    }

    public static string GetInfo()
    {
        Console.Write("Enter Employee Name : ");
        name = Console.ReadLine();

        Console.Write("Enter your Weekly Sales : ");
        WeeklySales = Convert.ToDouble(Console.ReadLine());

        return name;
    }
}

}

どんな助けでも喜んでいただければ幸いです:)

4

3 に答える 3

0

静的メソッドはクラスのインスタンスを必要としません。それらはコンパイル時に静的に解決され、インスタンス メソッドの場合のように動的ではありません。メソッド定義から静的を削除するか、正しい方法でそれらを呼び出します

于 2013-08-10T07:36:44.117 に答える
0
Employee yuki = new Employee();
yuki.GrossPay();

というより:

Employee.GrossPay();

静的メソッドを間違った方法で使用しようとしています。

于 2013-08-10T07:02:19.410 に答える