Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Would this work for this program? Chapter 4 Program Problems 5 Create an applica

ID: 3857089 • Letter: W

Question

Would this work for this program? Chapter 4 Program Problems 5

Create an application that lets users convert distances to and from inches, feet, and yards.

Form objects: 2 Listboxes, User Input for distance, 1 Output Label, 1 Acceptance Button

If(decimal.TryParse(txtBoxUserIn.Text, out userdisent))

{

//Check for item selection from twodifferent listboxes & store selection in variable in userchoice1 and userchoice2

if(theFirstListBox.SelectedIndex != -1)

{

if(theSecondListBox.SelectedIndex != -1)

{

userchoice1 = theFirstListBox.SelectedItem.ToString();

userchoice2 = theSecondListBox.SelectedItem.ToString();

switch (userchoice1)

{

case "Inches":

if (userchoice2 == 0)

{

//inches to inches equation

lblDistance.Text = answer.ToString() + " inches to inches";

}

else if (userchoice2 == 1)

{

//inches to feet equation

decimal answer = userdisent / 12;

lblDistance.Text = answer.ToString() + " feet from inches";

}

else if (userchoice2 == 2)

{

//inches to yards equation

lblDistance.Text = answer.ToString() + " yards from inches";

}

break;

case "Feet":

//Something similiar

break;

case "Yards":

//Something similiar

break;

default:

break;

}

}

}

}

Explanation / Answer

DistanceConvertorForm
-----------------------------------------------
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 Distance_Converter
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnConvert_Click(object sender, EventArgs e)
        {
            String strFrom, strTo;

            double dblOutput, dblInput;
            dblInput = Convert.ToDouble(txtInput.Text);
          
          
            if (lstFrom.SelectedIndex != -1)
            {
                strFrom = lstFrom.SelectedItem.ToString();
                switch (strFrom)
                {
                    case "Inches":
                        strFrom = "Inches";
                        break;
                    case "Feet":
                        strFrom = "Feet";
                        break;
                    case "Yard":
                        strFrom = "Yard";
                        break;
                }
                if (lstTo.SelectedIndex != -1)
                {
                    strTo = lstTo.SelectedItem.ToString();
                    switch (strTo)
                    {
                        case "Inches":
                            strTo = "Inches";
                            break;
                        case "Feet":
                            strTo = "Feet";
                            break;
                        case "Yard":
                            strTo = "Yards";
                            break;
                    }
                    if (strFrom == "Inches" && strTo == "Inches" || strFrom == "Inches" && strTo == "Inches")
                    {
                        lblOut.Text = dblInput.ToString("n2");
                    }
                    else if (strFrom == "Feet" && strTo == "Feet" || strFrom == "Feet" && strTo == "Feet")
                    {
                        lblOut.Text = dblInput.ToString("n2");
                    }
                    else if (strFrom == "Yards" && strTo == "Yards" || strFrom == "Yards" && strTo == "Yards")
                    {
                        lblOut.Text = dblInput.ToString("n2");
                    }
                    else if (strFrom == "Feet" && strTo == "Inches")
                    {
                        dblOutput = dblInput * 12;
                        lblOut.Text = dblOutput.ToString("n2");
                    }
                    else if (strFrom == "Yards" && strTo == "Inches")
                    {
                        dblOutput = dblInput * 36;
                        lblOut.Text = dblOutput.ToString("n2");
                    }
                    else if (strFrom == "Yards" && strTo == "Feet")
                    {
                        dblOutput = dblInput * 3;
                        lblOut.Text = dblOutput.ToString("n2");
                    }
                    else if (strFrom == "Inches" && strTo == "Feet")
                    {
                        dblOutput = dblInput / 12;
                        lblOut.Text = dblOutput.ToString("n2");
                    }
                    else if (strFrom == "Inches" && strTo == "Yards")
                    {
                        dblOutput = dblInput / 36;
                        lblOut.Text = dblOutput.ToString("n2");
                    }
                    else if (strFrom == "Feet" && strTo == "Yards")
                    {
                        dblOutput = dblInput / 3;
                        lblOut.Text = dblOutput.ToString("n2");
                    }

                }
                else
                {
                    MessageBox.Show("please select an item");
                }
            }
            else
            {
                MessageBox.Show("please select an item");
            }
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote