Question: C# Computer programming, can I get some help with the following code I have started. Write a program name DeskGUI that computes the price of
C# Computer programming, can I get some help with the following code I have started.
Write a program name DeskGUI that computes the price of a desk and whose button Click Event calls the following methods: A method to accept the number of drawers in the desk as input from the key board. This method returns the number of drawers to the SelectDesk_Click event. A method to accept an input and return the type of wood, m for mahogany, o for oak, or p for pine. A method that accepts the number of drawers and wood type and calculates the cost of the desk based on the following o Pine desks are $100 o Oak desks are $140 o All other woods are $180 o A $30 surcharge is added for each drawer. o This method returns the cost to the SelectDesk_Click event. A method to display all the details and final price. All methods are void methods and receive ref or out parameters as appropriate.
Error Checking:
- The program should only accept a whole number for the number of drawers between 1 to 5. If the user enters an invalid value, an error message should be displayed and the user should be prompted to enter a valid entry. The error checking should occur in the method that accepts the number of drawers.
- The program should only accept 'm', 'o' and 'p' as the type of wood. If the user enters an invalid value, an error message should be displayed and the user should be prompted to enter a valid entry. The error checking should occur in the method that accepts the type of wood.
When running the code I have it is not working, need help correcting what I have please.
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 DeskGUI { public partial class Form1 : Form { public Form1() { InitializeComponent(); } bool bContinue = true; private void cmdOrder_Click(object sender, EventArgs e) { int numberOfDrawers = 0; string typeOfWood = ""; double cost = 0.0; bContinue = true;
numberOfDrawers = GetDrawers(); typeOfWood = txtWood.Text;
if (bContinue == true) { cost = GetCost(numberOfDrawers, typeOfWood); DisplayOrder(numberOfDrawers, typeOfWood, cost); } } private int GetDrawers() { int drawers = 0; drawers = Convert.ToInt32(txtDrawers.Text); if (drawers <= 0 || drawers > 5) { MessageBox.Show("Drawers must be between 1 and 5"); bContinue = false; } return drawers; } private string GetWood(string wood) { //assigning value to type of wood string ch; wood.ToLower(); if (wood == "Mahogany") ch = "m"; else if (wood == "Oak") ch = "o"; else if (wood == "Pine") ch = "p"; else ch = "null"; { MessageBox.Show("Wood type is invalid, please enter the correct type of wood."); bContinue = false; } return ch; } private double GetCost(int drawers, string wood) { //Calculates price double cost; if (wood == "p") cost = 100 + (drawers * 30); else if (wood == "o") cost = 140 + (drawers * 30); else cost = 180 + (drawers * 30); return cost; } string DisplayOrder(int drawers, string wood, double cost) { //display values string result = "Number of drawers are " + drawers + " Desk is made up of " + wood + " Cost of the table is $ " + cost; return result;
} } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
