Ask Question
17 February, 04:44

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_Clic

+1
Answers (1)
  1. 17 February, 08:36
    0
    Following code takes the information about the wood from the user, do the process of calculating the value according to there type and numbers, then add the surcharge to it while giving the answer to the user.

    For differentiating the type of woof i used the if then else statement while i used switch case statement for assigning the appropriate value according to the types of the wood will be processing in the program.

    The code is given below:

    Explanation:

    Code:

    namespace std; / / any name instead of std.

    {

    class Program

    { / / starting the main program

    static void Main (string[ ] args)

    {

    int numberOfDrawers = 0;

    string deskWoodType = "o";

    double cost = 0;

    drawersMeth (numberOfDrawers);

    woodTypeMeth (deskWoodType);

    CalculateCostMeth (numberOfDrawers, cost, deskWoodType);

    OutPutCostMeth (deskWoodType, cost, numberOfDrawers);

    }//end main

    private static void drawersMeth (int numberOfDrawers)

    {

    int numOfDrawers;

    Console. WriteLine ("Enter the number of desk drawers");

    numOfDrawers = Convert. ToInt16 (Console. ReadLine ());

    numberOfDrawers = numOfDrawers;

    }//end drawersMeth

    private static string woodTypeMeth (string deskWoodType)

    {

    Console. WriteLine ("Enter the desk wood type. (eg. type mahogany, oak, or pine) ");

    deskWoodType = Convert. ToString (Console. ReadLine ());

    switch (deskWoodType)

    {

    case "mahogany":

    {

    deskWoodType = "m";

    break;

    }

    case "oak":

    {

    deskWoodType = "o";

    break;

    }

    case "pine":

    {

    deskWoodType = "p";

    break;

    }

    default:

    {

    deskWoodType = "error";

    break;

    }

    }

    return deskWoodType;

    }/ / end woodTypeMeth

    private static int CalculateCostMeth (string deskWoodType, int numberOfDrawers, int cost)

    {

    int pine = 100;

    int oak = 140;

    int other = 180;

    int surchage = 30;

    if (deskWoodType = = "p")

    cost = surchage + (numberOfDrawers * pine);

    else if (deskWoodType = = "o")

    cost = surchage + (numberOfDrawers * oak);

    else

    cost = surchage + (numberOfDrawers * other);

    return cost;

    }/ / end CalculateCostMeth

    private static void OutPutCostMeth (int numberOfDrawers, string deskWoodType, int cost)

    {

    double totalCost = cost;

    Console. WriteLine ("The number of drawers is {0}", numberOfDrawers);

    Console. WriteLine ("The wood finish you have selected is ", deskWoodType);

    Console. WriteLine ("The total cost is {0}", totalCost);

    }//end outputCost

    }//end class

    }//end nameSpace
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “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 ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers