-1

次のコードはすべてを表示します。デフォルトのコンストラクターで表示できます。残念ながら、従業員 ID 番号と支払いの結果が表示されません。コードを書いたときにエラーは発生しませんでした。したがって、私にはまったくわかりません。

//class for FullTimeEmployee
namespace EmPloyee
{
public class FullTimeEmployee  //object
{
    private string FEmployeeFName, FEmployeeLName;
    private double FEmployeeID;
    private double FEmployeeWorkHour;
    private const double FEmployeePayRate = 20.00;
    private double GrossPay, RegPay, OTPay;

    //No Args Constructor, Default Constructor
    public FullTimeEmployee()
    {
        FEmployeeFName = "Arthur";
        FEmployeeLName = "Chen";
        FEmployeeID = 1000;
        FEmployeeWorkHour = 60;
        RegPay = calcRegPay();
        OTPay = CalOTPay();

    }

    //Constructor 
    public FullTimeEmployee(string FFName, string FLName, double FID, double FHours)
    {
        FEmployeeFName = FFName;
        FEmployeeLName = FLName;
        FID = FEmployeeID;
        FEmployeeWorkHour = FHours;
        //FEmployeePayRate = FPRate;

    }

    //Accessor Methods

    //get name
    public string GetFName()
    {
        return FEmployeeFName + " " + FEmployeeLName; 
    }

    //get ID
    public double getID()
    {
        return FEmployeeID;
    }

    //get Payrate
    public double getPayRate()
    {
        return FEmployeePayRate;
    }

    //get hours
    public double getHours()
    {
        return FEmployeeWorkHour;
    }

    //**********************************
    //******Calculate GrossPay**********
    //**********************************

    //Calculate RegularPay
    private double calcRegPay()
    {
        double RegPay;
        if (FEmployeeWorkHour >= 0 && FEmployeeWorkHour <= 38)
        {
            RegPay = FEmployeeWorkHour * FEmployeePayRate;
        }
        else
        {
            RegPay = 38 * FEmployeePayRate;
        }

        return RegPay;
    }

    //get Regular Pay
    public double getRegPay()
    {
        return RegPay;
    }

    //calculate OverTime Pay
    private double CalOTPay()
    {
        double OTPay;
        if (FEmployeeWorkHour >= 0 && FEmployeeWorkHour <= 38)
        {
            OTPay = 0;
        }
        else
        {
            OTPay = (FEmployeeWorkHour - 38) * FEmployeePayRate * 1.5;
        }

        return OTPay;
    }

    //get OTPay
    public double getOTPay()
    {
        return OTPay;
    }

    //get Gross Pay
    public double getGrossPay()
    {
        return GrossPay = RegPay + OTPay;
    }

} //end FullTimeEployee Class

} //end Name Space


//Employee Driver 
namespace EmPloyee
{
class EmployeeDriver
{
    static void Main(string[] args)
    { 
        //switch
        char Response;
        Response = 'X';

          String Question= "Select F or f if you want to Create a Full Time Employee\n"
            + "Or P or p to create a Part-Time Employee";
        Console.WriteLine(Question);
        String inputS =Console.ReadLine();

        Response=Convert.ToChar(inputS.Substring(0,1));

        switch (Response) 
        {
            case 'F': case 'f':
                CreateFullTime();
                break;

            case 'P': case 'p':
          //      CreatePartTime();
                break;

        } //end Switch
        Console.WriteLine("Hit Any Key to Exit");
        Console.ReadLine();


    } //end main


    public static void CreateFullTime()
    {    //get output for default constructor
        FullTimeEmployee myFT;

        myFT = new FullTimeEmployee();

        //outputing with formatted strings
        Console.WriteLine("Full Time Employee's First Name: " + myFT.GetFName());
        Console.WriteLine("Full Time Employee's ID: " + myFT.getID());
        Console.WriteLine("Full Time Employee's Hour: " + myFT.getHours().ToString("n2"));
        Console.WriteLine("Full Time Employee's PayRate: " + myFT.getPayRate().ToString("C2"));
        Console.WriteLine("Full Time Employee's Regular Pay: " + myFT.getRegPay().ToString("C2"));
        Console.WriteLine("Full Time Employee's Over Time Pay: " + myFT.getOTPay().ToString("C2"));
        Console.WriteLine("Full Time Employee's Net Pay: " + myFT.getGrossPay().ToString("C2"));


        //some temporary variables
        string LN = " ", FN = " ";
        double FId = -8888;
        double FHrs = -10;
        // bool checkFN=false;
        bool CheckID = false;
        bool CheckHour = false;




        Console.WriteLine("Enter Your First Name");
        FN = Console.ReadLine();

        //do  //get information for first name
        //{
        //    try
        //    {
        //        FN = Console.ReadLine();

        //    }
        //    catch (FormatException fmte)
        //    {
        //        Console.WriteLine(fmte.Message);
        //        // flag = true;

        //    }
        //    if (FN = " ")
        //    {
        //        Console.WriteLine("Please Enter a Valid Name");
        //        // flag = true;
        //    }
        //} while (FN = " ");

        Console.WriteLine("Enter Your Last Name");

        LN = Console.ReadLine();



        //input the correct ID number
        //Console.WriteLine("Enter Your ID Number");
        do
        {
            try
            {
                Console.WriteLine("Enter Your ID Number");
                string inputid = Console.ReadLine();
                FId = double.Parse(inputid);

                //  FId = double.Parse(Console.ReadLine());

            }
            catch (FormatException fmte)
            {
                Console.WriteLine(fmte.Message);

            }
            if (FId >= 1001 && FId <= 9999)
            {
                CheckID = true;
            }
            else
            {

                Console.WriteLine("ID Number Must Be 4 Digit Number "
                + "and greater than 1000");
            }
        } while (!CheckID);


        //Enter workhous


        do
        {
            try
            {
                Console.WriteLine("Enter Hours");
                string inputhr = Console.ReadLine();

                FHrs = double.Parse(inputhr);
            }
            catch (FormatException fmte)
            {
                Console.BackgroundColor = ConsoleColor.Red;
                Console.WriteLine("Dude\n"
                      + "It is NOT a Legic Number!!" + fmte.Message);


            }
            if (FHrs > 0 && FHrs <= 65)
            {
                CheckHour = true;
            }
            else
            {
                Console.WriteLine("Please Enter a Positive Number\n"
                + "And the maxmium number is 65!!!");
            }

        } while (!CheckHour);

        FullTimeEmployee YrFT;
        YrFT = new FullTimeEmployee(FN, LN, FId, FHrs);

        //outputing
        Console.WriteLine("FT Employee's Name: " + YrFT.GetFName());
        Console.WriteLine("FT Employee's ID: " + YrFT.getID());
        Console.WriteLine("FT Employee's Hours: " + YrFT.getHours().ToString("n2"));
        Console.WriteLine("FT Employee's Pay Rate: " + YrFT.getPayRate().ToString("c2"));
        Console.WriteLine("FT Employee's Regular Pay: " + YrFT.getRegPay().ToString("C2"));
        Console.WriteLine("FT Employee's Over Time Pay: " + YrFT.getOTPay().ToString("C2"));
        Console.WriteLine("FT Employee's Net Pay: " + YrFT.getGrossPay().ToString("c2"));

    }
      }
}
4

2 に答える 2

1

クラスはかなりまとまりがありませんが、エラーを見つけることができました。下記参照...

 //Constructor 
    public FullTimeEmployee(string FFName, string FLName, double FID, double FHours)
    {
        FEmployeeFName = FFName;
        FEmployeeLName = FLName;
        FEmployeeID = FID; // This was backwards in your code.
        FEmployeeWorkHour = FHours;
        RegPay = calcRegPay(); // You need this line and the next one...
        OTPay = CalOTPay(); // to trigger your payment calculations.
    }
于 2013-09-22T02:21:29.343 に答える
0

引数付きのコンストラクターでは、支払い率がコメントアウトされています。引数のないコンストラクターでは、支払い率が計算されますが、代わりに 4 つの引数のコンストラクターが呼び出されているため、このコンストラクターは呼び出されません。

従業員 ID は、等号の反対側にあります。入力変数の値をFIDフィールドにあるものに再割り当てしていますFEmployeeID

代わりにこれを試してください:

// Constructor 
public FullTimeEmployee(string FFName, string FLName, double FID, double FHours, double FPRate)
{
    FEmployeeFName = FFName;
    FEmployeeLName = FLName;
    FEmployeeID = FID;
    FEmployeeWorkHour = FHours;
    FEmployeePayRate = FPRate;
}

コンストラクターのすべての引数が等号の右側にあることに注意してください。

this()別のオプションとして、引数なしのコンストラクターに 4-(まあ、5-)args コンストラクターからデフォルト値を挿入させたい場合は、atを使用して 4/5-args コンストラクターに引数なしのコンストラクターを呼び出させることができます。宣言の終わり。

// Constructor 
public FullTimeEmployee(string FFName, string FLName, double FID, double FHours, double FPRate) 
    : this()
{
    FEmployeeFName = FFName;
    FEmployeeLName = FLName;
    FEmployeeID = FID;
    FEmployeeWorkHour = FHours;
    FEmployeePayRate = FPRate;
}
于 2013-09-22T02:09:57.753 に答える