using System;
// app named Desks
public class Desks
{
// has main()
public static void Main()
{
Console.WriteLine("In main()");
// set up the variables Main() will need.
int numDrawers;
char woodType;
float cost;
// Call the method to get the number of drawers from the user
numDrawers = getNumDrawers();
Console.WriteLine("You chose {0} drawers for this desk.", numDrawers);
// Call the method to get the type of wood from the user
woodType = getWoodType();
Console.WriteLine("The wood type was set as {0}", woodType);
return;
}
// -method - accepts input for number of drawers from user, returns that number to main()
public static int getNumDrawers()
{
Console.WriteLine("In getNumDrawers()");
string input;
Console.WriteLine("How many drawers would you like this desk to have? ");
input = Console.ReadLine();
return Convert.ToInt32(input);
}
// - method - accepts type of wood from user, returns to main()
public static char getWoodType()
{
string input;
char woodType;
// -- m=mahogany, o=oak, p=pine
Console.WriteLine("In getWoodType()");
Console.WriteLine("What type of wood would you like?");
Console.WriteLine("Enter 'o' for Oak, 'm' for Mahogany, or 'p' for Pine:");
input = Console.ReadLine();
woodType = input[0]; // it's a char, so just grab the first char
if (woodType == 'm'){
Console.WriteLine("You chose a mahogany desk.");
}
else if (woodType == 'o'){
Console.WriteLine("You chose an oak desk.");
}
else if (woodType == 'p'){
Console.WriteLine("You chose a pine desk.");
}
else{
Console.WriteLine("You chose some kind of unknown wood. We'll default to pine.");
woodType = 'p';
// This would be a good place to do input checking. Stick this in a loop and keep
// getting input until the user picks a valid option.
}
return woodType;
}
// - method accepts #drawers & wood type, calculates cost, returns to main()
public static float calcDeskCost(int numDrawers, char woodType)
{
// -- pine=$100, oak=$140, other wood = $180
// -- each drawer +$30
Console.WriteLine("In calcDeskCost()");
return 1.0f;
}
// - method - display all details and final price
public static void display(int numDrawers, char woodType, float cost)
{
Console.WriteLine("in display()");
return;
}
}
Next, we've implemented the getWoodType() method, and called it from Main.
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.