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

Chapter 7 page 312 Excersise 9a. Create a console-based application that compute

ID: 3660578 • Letter: C

Question

Chapter 7 page 312 Excersise 9a. Create a console-based application that computes the price of a desk and whos Main() method calls for four other methods: A method to accept the number of drawers in the desk as input from the keyboard. This method returns the number of drawers to the main () method. A method to accept as 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: Pine desks are $100. Oak desks are $140. All other woods are $180. A $30 surcharge is added for each drawer. This method to diplay all the details the the final price. Save as desk.cs

Explanation / Answer

public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { int intDrawersPerDesk = 0; int intAllDesks = 0; //1. checking if textBox of wood type is empty: string strWoodType = textBoxWoodType.Text; if (strWoodType != String.Empty) { //2. checking if its a number for number of desks if (int.TryParse(textBoxDrawsPerDesk.Text.Trim(), out intDrawersPerDesk)) { //3. checking if its a number for number of drawers if (int.TryParse(textBoxAllDesks.Text.Trim(), out intAllDesks)) { //4. calculations, and checking of any of the numbers are zero int intAllDrawers = NumberOfDrawers(intDrawersPerDesk, intAllDesks); if (intAllDrawers > 0) { //5. checking exact wood type string strShortWoodType = WoodType(strWoodType); if (strShortWoodType != "error") { float fTotal = CalculateTotalCost(strWoodType, intAllDrawers); MessageBox.Show("The total code is " + fTotal + "."); } else MessageBox.Show("Please enter the correct wood type (mahogany, oak or pine)."); } else MessageBox.Show("Sum of all drawers is zero. Please higher the number of desk or drawers."); } } } else MessageBox.Show("Please enter the correct wood type."); } private int NumberOfDrawers(int intDrawersPerDesk, int intAllDesks) { return intDrawersPerDesk * intAllDesks; } public string WoodType(string strTreeType) { switch (strTreeType) { case "mahogany": { strTreeType = "m"; break; } case "oak": { strTreeType = "o"; break; } case "pine": { strTreeType = "p"; break; } default: { strTreeType = "error"; break; } } return strTreeType; } private float CalculateTotalCost(string type, int intAllDrawers) { float fCost = 0f; if (type == "p") fCost = 100 * intAllDrawers; else if (type == "o") fCost = 140 * intAllDrawers; else fCost = 180 * intAllDrawers; //adding a surcharge for each drawer: fCost = fCost + (intAllDrawers * 30); return fCost; } }

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