Adapt the following code to run in a windows form and also add a button to reset the input length and width boxes.
namespace PaintingEstimate
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Program computes the cost of painting the room");
//inputs room length and width
Console.Write("Enter room length: ");
int length = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter room width: ");
int width = Convert.ToInt32(Console.ReadLine());
//calls method
int totalPrice = ComputePrice(length, width);
Console.WriteLine("Total price: ${0}", totalPrice);
Console.ReadKey();
}
//method computes work price
static int ComputePrice(int length, int width)
{
//price per square foot
int price = 6;
//ceiling
int ceil = 9;
int totalSquare = width * ceil * 2 + length * ceil * 2;
return price * totalSquare;
}
}
}
using System;
using System.Windows.Forms;
namespace PaintingEstimate
{
public partial class MainForm : Form
{
public MainForm()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
}
void Button1Click(object sender, EventArgs e)
{
textBox1.Text="0";
textBox2.Text="0";
textBox3.Text="0";
}
void Button2Click(object sender, EventArgs e)
{
//inputs room length and width
int length = Convert.ToInt32(textBox1.Text);
int width = Convert.ToInt32(textBox2.Text);
//calls method
int totalPrice = ComputePrice(length, width);
textBox3.Text = Convert.ToString(totalPrice);
}
//method computes work price
static int ComputePrice(int length, int width)
{
//price per square foot
int price = 6;
//ceiling
int ceil = 9;
int totalSquare = width * ceil * 2 + length * ceil * 2;
return price * totalSquare;
}
}
}
Comments
What does the code look like to get these results?
Leave a comment