Answer to Question #327403 in C# for Dave

Question #327403

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;

    }

  }



}




1
Expert's answer
2022-04-11T14:02:51-0400
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;
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

Dave
11.04.22, 19:17

What does the code look like to get these results?

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS