C# Need assistance with programming methods with visual basic. I can not get thi
ID: 3600992 • Letter: C
Question
C# Need assistance with programming methods with visual basic.
I can not get this code to work, I have been working on it for more than a day now. I am at a loss. Ive tried many different ways and its just not working. Please help!
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.
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();
}
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 == "m")
ch = "Mahogany";
else if (wood == "o")
ch = "Oak";
else if (wood == "p")
ch = "Pine";
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;
}
bool bContinue = true;
}
private void cmdOrder_Click(object sender, EventArgs e)
{
int numberOfDrawers = 0;
string typeOfWood = "";
double cost = 0.0;
bool bContinue = true;
numberOfDrawers = GetDrawers();
typeOfWood = txtWood.Text;
if (bContinue == true)
{
cost = GetCost(numberOfDrawers,
typeOfWood);
DisplayOrder(numberOfDrawers, typeOfWood, cost);
}
}
}
Explanation / Answer
You are not calling the GetWood function. In the function cmdOrder_Click you should change this:
typeOfWood = GetWood(txtWood.Text)
Also, the redeclaration of the boolean variable bContinue creates a local variable for cmdOrder_Click, you should directly set bContinue=true instead of declaring it as bool bContinue=true
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.