如何使用分配要求中的某些进行计算

命名空间PowerBill {     公共局部类frmMain:表单     {         //提供默认值         客户c =新客户();

    public frmMain()
    {
        InitializeComponent();
    }

    // user select Residential
    private void radResidential_CheckedChanged(object sender, EventArgs e)
    {
        HideSecondInput();
    }

    // user selects Commercial
    private void radCommercial_CheckedChanged(object sender, EventArgs e)
    {
        HideSecondInput();
    }

    // user selects Industrial
    private void radIndustrial_CheckedChanged(object sender, EventArgs e)
    {
        ShowSecondInput();
    }

    // hide second input prompt and txt box; 
    // adjust prompt for first input: generic kWh
    private void HideSecondInput()
    {
        lblkWh1Prompt.Text = "Used kWh:";
        lblkWh2Prompt.Visible = false;
        txtkWh2.Visible = false;
        txtkWh1.Focus(); // focus on first input box
    }

    // hide second input prompt and txt box; 
    // adjust prompt for first input: peak kWh
    private void ShowSecondInput()
    {
        lblkWh1Prompt.Text = "Peak kWh:";     
        lblkWh2Prompt.Visible = true;
        txtkWh2.Visible = true;
        txtkWh1.Focus(); // focus on first input box
    }



    // calculate customer charge
    private void btnCalculate_Click(object sender, EventArgs e)
    {
        int kWh = 0, peakKWh= 0, offPeaKWh = 0;
        decimal charge = 0; 
        if (radResidential.Checked)
        {
            kWh = Convert.ToInt32(txtkWh1.Text);
            charge = c.ResidentialCharge(kWh);
            lblCharge.Text = charge.ToString("c");
            //if(Validator.IsPresent(txtkWh1, "kWh") &&
            //   Validator.IsNonNegativeInteger(txtkWh1, "kWh"))
            {


            }
        }
        else if (radCommercial.Checked)
        {
            //if (Validator.IsPresent(txtkWh1, "Used kWh") &&
            //   Validator.IsNonNegativeInteger(txtkWh1, "kWh"))
            {
                kWh = Convert.ToInt32(txtkWh1.Text);
                charge = CommercialCharge(kWh);
                lblCharge.Text = charge.ToString("c");
            }
        }
        else // must be industrial
        {
            //if (Validator.IsPresent(txtkWh1, "Peak kWh") &&
            //    Validator.IsNonNegativeInteger(txtkWh1, "Peak kWh") &&
            //    Validator.IsPresent(txtkWh2, "Off-peak kWh") &&
            //    Validator.IsNonNegativeInteger(txtkWh2, "Off-peak kWh"))
            {
                peakKWh = Convert.ToInt32(txtkWh1.Text);
                offPeaKWh = Convert.ToInt32(txtkWh2.Text);
                charge = IndustrialCharge(peakKWh, offPeaKWh);
                lblCharge.Text = charge.ToString("c");
            }
        }
        // display charge
        lblCharge.Text = charge.ToString("c");
    }

    // calculate charge for residential customer
    private decimal ResidentialCharge(int kWh)
    {
        const decimal BASE_CHARGE = 6;
        const decimal CHARGE_PER_kWh = 0.052m;
        decimal charge = BASE_CHARGE + kWh * CHARGE_PER_kWh;
        return charge;
    }

    // calculate charge for commercial customer
    private decimal CommercialCharge(int kWh)
    {
        const decimal BASE_CHARGE = 60;
        const int THRESHOLD = 1000;
        const decimal CHARGE_PER_kWh = 0.045m;
        decimal charge = BASE_CHARGE;
        if (kWh > THRESHOLD)
            charge += (kWh - THRESHOLD) * CHARGE_PER_kWh;
        return charge;
    }

    // calculate charge for industrial customer
    private decimal IndustrialCharge(int peakKWh, int offPeakKWh)
    {
        const decimal PEAK_BASE_CHARGE = 76;
        const decimal OFF_PEAK_BASE_CHARGE = 40;
        const int THRESHOLD = 1000;
        const decimal PEAK_CHARGE_PER_kWh = 0.065m;
        const decimal OFF_PEAK_CHARGE_PER_kWh = 0.028m;
        decimal charge, peakCharge, offPeakCharge;
        // calculate charge for peak kWh
        peakCharge = PEAK_BASE_CHARGE;
        if (peakKWh > THRESHOLD)
            peakCharge += (peakKWh - THRESHOLD) * PEAK_CHARGE_PER_kWh;
        // calculate charge for off-peak kWh
        offPeakCharge = OFF_PEAK_BASE_CHARGE;
        if (offPeakKWh > THRESHOLD)
            offPeakCharge += (offPeakKWh - THRESHOLD) * OFF_PEAK_CHARGE_PER_kWh;
        // add the two charges
        charge = peakCharge + offPeakCharge;
        return charge;
    }


    // to clear the textbox
    private void btnClear_Click(object sender, EventArgs e)
    {
        txtkWh1.Text = "";
        txtkWh1.Text = "";
        lblCharge.Text = "";
        radResidential.Checked = true;
        txtkWh1.Focus();
    }

    private void btnExit_Click(object sender, EventArgs e)
    {
        Application.Exit(); //Close(); 
    }

    private void btnAdd_Click(object sender, EventArgs e)
    {

    }
}

}

嗨,您好

我已经完成了这项作业,但是不确定下一步如何完成 我认为作业也想使用读取功能进行其他方法计算

有什么建议帮助吗

这是作业

在添加新客户的数据时,或在应用程序关闭之前, 客户数据需要写入文件中。下次启动应用程序时,将从中读取数据 此文件允许更多添加更多客户。 您的应用程序应始终显示上面列出的客户数据的当前集合。在 另外,还要求您计算并显示以下统计信息: 客户总数, 每种客户类型的费用总和(三个值),以及 所有费用的总和。 步骤1:定义客户类别 将名为CustomerData的类库项目添加到您的Lab 1解决方案中。在您的项目中进行此项目 解。在CustomerData项目中,定义代表客户的Customer类。至少, 该课程应具有: 上述数据的公共属性, 一个或多个构造函数, 方法CalculateCharge根据以下方法计算此客户的费用金额: 规则,以及 返回显示字符串的ToString()方法。