In: Computer Science
Part 2: An electric company charges to their customers based on Kilowatt-Hours (Kwh) used. The rules to compute the charge are: First 100 Kwh, 35 cents per Kwh Each of the next 100 Kwh (up to 200 Kwh), 45 cents per Kwh (the first 100 Kwh used is still charged at 35 cents each) Each of the next 300 Kwh (up to 500 Kwh) 65 cents per Kwh All Kwh over 500, 80 cents per KH Create a C# Form with a textbox to enter Kwh used, a read-only textbox to display the electricity charges, and a button to compute the charges. The Kwh used could be a number with decimals. Requirements: 1. Input validation: Use the KWH textbox validating event to ensure the KWH cannot exceed 2000. Test your program with (1) Kwh=4500, (2) Kwh = 350 2. Turn in the form’s screenshot and the code.
In C# using Visual Studios 2017 Windows form app
C# code
============================================================================================
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ElectricityBill
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int kwh;
float bill=0;
kwh = Convert.ToInt32(KWH.Text);
if(kwh<0 || kwh>2000)
{
textBox1.Text = "KWH can not exceed 2000";
}
else
{
if(kwh<=100)
{
bill = 35 * kwh;
}
else if(kwh <= 200)
{
bill = 35 *100+45*(kwh-100);
}
else if (kwh <= 500)
{
bill = 35 * 100 + 45 *100+65 *(kwh - 200);
}
else if (kwh <= 2000)
{
bill = 35 * 100 + 45 * 100 + 65*300 +80* (kwh - 500);
}
bill = bill / 100;
textBox1.Text = "Bill is: $" + bill.ToString();
}
}
}
}
============================================================================================
Output