Beispiel #1
0
        public void IndustrialChargeWithHighUsageTestSucc()
        {
            // Arrange
            decimal     usagePeak      = 2000m; //high usage during peak hours defined as > 1000 kWh
            decimal     usageOff       = 3000m; //high usage during off-peak hours defined as > 1000 kWh
            CustomerInd customerInd    = new CustomerInd(accountNumber, accountName, custType, usagePeak, usageOff);
            decimal     expectedCharge = 237;
            decimal     actualCharge;

            //Act
            actualCharge = customerInd.CalculateCharge();

            //Assert
            Assert.AreEqual(expectedCharge, actualCharge);
        }
Beispiel #2
0
        // calculate and display bill to pay
        private void btnCalculate_Click(object sender, EventArgs e)
        {
            // local declaration
            decimal kWh     = 0m;       //input: kWh used for residential or commercial customers
            decimal kWhPeak = 0m;       //input: kWh used for industrial customers during peak hours
            decimal kWhOff  = 0m;       //input: kWh used for industrial customers during off-peak hours
            string  customer;           //input: customer type
            char    custType;           //customer type (R, C, or I)

            // obtain type of customer input from dropbox list
            customer = cboCustomer.Text;

            //assign customer type
            switch (customer)
            {
            case "Residential":
                //focus on the input box
                txtAccountNo.Focus();

                //validate user input for kWh used
                if (validator.IsProvided(txtAccountNo, "Account Number") &&
                    validator.IsNonZeroPositiveInt(txtAccountNo, "Account Number") &&
                    validator.IsProvided(txtCustomerName, "Customer Name") &&
                    validator.IsString(txtCustomerName, "Customer Name") &&
                    validator.IsProvided(txtkWh, "Residential usage") &&
                    validator.IsNonNegativeInt(txtkWh, "Residential Usage"))
                {
                    //assign custType
                    custType = 'R';

                    //obtain input
                    kWh = Convert.ToDecimal(txtkWh.Text);

                    //create a Customer Object using data from text boxes
                    Customer c = new CustomerRes(Convert.ToInt32(txtAccountNo.Text), txtCustomerName.Text, custType, kWh);

                    //display charge amount in appropriate text box
                    txtBill.Text = c.CalculateCharge().ToString("c");

                    //add it to the list and display
                    customers.Add(c);
                    //DisplayCustomers();
                }
                break;

            case "Commercial":
                //focus on the input box
                txtAccountNo.Focus();

                //validate user input for kWh used
                if (validator.IsProvided(txtAccountNo, "Account Number") &&
                    validator.IsNonZeroPositiveInt(txtAccountNo, "Account Number") &&
                    validator.IsProvided(txtCustomerName, "Customer Name") &&
                    validator.IsString(txtCustomerName, "Customer Name") &&
                    validator.IsProvided(txtkWh, "Commercial usage") &&
                    validator.IsNonNegativeInt(txtkWh, "Commercial Usage"))
                {
                    //assign custType
                    custType = 'C';

                    //obtain input
                    kWh = Convert.ToDecimal(txtkWh.Text);

                    //create a Customer Object using data from text boxes
                    Customer c = new CustomerComm(Convert.ToInt32(txtAccountNo.Text), txtCustomerName.Text, custType, kWh);

                    //display charge amount in appropriate text box
                    txtBill.Text = c.CalculateCharge().ToString("c");

                    //add it to the list and display
                    customers.Add(c);
                    //DisplayCustomers();
                }
                break;

            case "Industrial":
                //validate user input for kWh used
                if (validator.IsProvided(txtAccountNo, "Account Number") &&
                    validator.IsNonZeroPositiveInt(txtAccountNo, "Account Number") &&
                    validator.IsProvided(txtCustomerName, "Customer Name") &&
                    validator.IsString(txtCustomerName, "Customer Name") &&
                    validator.IsProvided(txtkWhPeak, "Industrial peak hours usage") &&
                    validator.IsNonNegativeInt(txtkWhPeak, "Industrial peak hours usage") &&
                    validator.IsProvided(txtkWhOff, "Industrial off-peak hours usage") &&
                    validator.IsNonNegativeInt(txtkWhOff, "Industrial off-peak hours usage"))
                {
                    //assign custType
                    custType = 'I';

                    //obtain input(s)
                    kWhPeak = Convert.ToDecimal(txtkWhPeak.Text);
                    kWhOff  = Convert.ToDecimal(txtkWhOff.Text);

                    //create a Customer Object using data from text boxes
                    Customer c = new CustomerInd(Convert.ToInt32(txtAccountNo.Text), txtCustomerName.Text, custType, kWhPeak, kWhOff);

                    //display charge amount in appropriate text box
                    txtBill.Text = c.CalculateCharge().ToString("c");

                    //add it to the list and display
                    customers.Add(c);
                }
                break;

            default:
                break;
            }
        }