Answer:
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