Skip to content

Instantly share code, notes, and snippets.

@janell-baxter
Last active June 4, 2018 19:41
Show Gist options
  • Save janell-baxter/c5588b3b1fdae757f421be0ae1da823c to your computer and use it in GitHub Desktop.
Save janell-baxter/c5588b3b1fdae757f421be0ae1da823c to your computer and use it in GitHub Desktop.
Bakery Application (Introduction to Programming, Summer 2018): Using an Array to Store Menu Items
using System;
using System.Globalization;
using static System.Console;
namespace MegaByteBakery
{
class Bakery
{
// Two-dimensional array of menu items
public static string[,] menu = new string[,] { { "Filled Cupcake", "2.00" }, { "Garlic Bread", "1.50" }, { "Pie", "17.38" }, { "Cookie", "1.35" }, { "Fudge Brownie with Vanilla Icing", "2.60" }, { "Cheese Danish", "2.75" }, { "Croissant", "1.40" } };
public Bakery()
{
Cashier cashier = new Cashier();
cashier.Name = "Steve";
cashier.Greet();
Menu();
cashier.TakeOrder(this);
Console.Clear();
Console.WriteLine("Thank you for your Mega Byte Bakery order: ");
Console.WriteLine(Order.items);
Console.WriteLine("Your total is: $" + Order.total);
Console.WriteLine("Press any key to exit");
Console.ReadKey();
}
public void Menu()
{
WriteLine("Mega Bytes Bakery Menu\n---------------------");
//print out each item (not formatted)
//foreach (string s in menu)
//{
// WriteLine("{0} ", s);
//}
for (int i = 0; i < menu.GetLength(0); i++)
{
//Console.WriteLine("{0}: {1:C}", menu[i, 0], menu[i, 1]);
double price = Convert.ToDouble(menu[i, 1]);
string output = price.ToString("C", CultureInfo.CurrentCulture);
Console.WriteLine((i+1) + ") " + menu[i,0] + ": " + output + " each");
}
}
}
}
using System;
using static System.Console;
namespace MegaByteBakery
{
class Cashier
{
public string Name;
//constructor
public Cashier()
{ }
public void Greet()
{
WriteLine(Name + ": Hello and welcome to Mega Bytes!\n");
}
public void TakeOrder(Bakery bakery)
{
string input = "yes";
Console.Clear();
bakery.Menu();
AddItem();
WriteLine("Would you like anything else? Please enter yes or no:");
input = ReadLine();
if (input != "no")
{
TakeOrder(bakery);
}
}
private void AddItem()
{
string input;
string currentItem = "";
string currentPrice = "";
int index;
int amount;
WriteLine(Name + ": What would like you like to order? Enter the number of the item.");
input = ReadLine();
index = Convert.ToInt32(input);
currentPrice = Bakery.menu[(index - 1), 1];
currentItem = Bakery.menu[(index - 1), 0];
WriteLine(currentItem + ". Excellent choice. How many would you like?");
input = ReadLine();
amount = Convert.ToInt32(input);
Order.total += Convert.ToDecimal(currentPrice) * amount;
if (amount >= 2)
{
Order.items += amount + " " + currentItem + " orders: $" + (Convert.ToDecimal(currentPrice) * amount) + "\n";
WriteLine(amount + " orders of our delicious " + currentItem + " Byte will be $" + (Convert.ToDecimal(currentPrice) * amount));
}
else
{
Order.items += amount + " " + currentItem + " order: $" + (Convert.ToDecimal(currentPrice) * amount) + "\n";
WriteLine(amount + " order of our delicious " + currentItem + " Byte will be $" + Convert.ToDecimal(currentPrice) * amount);
}
WriteLine("Current total: $" + Order.total);
}
public double Calculate(string _input, double _price)
{
//how many of item * price
double total = Convert.ToDouble(_input) * _price;
return total;
}
public void Serve() { }
public void Advertise() { }
}
}
namespace MegaByteBakery
{
class Order
{
public static decimal total = 0;
public static string items = "";
}
}
/*
* [Your Title]
* by Your Name, Date
*
* This work is a derivative of
* "Bakery Application: Using an Array to Store Menu Items"
* by the Summer 2018 Introduction to Programming class (iam.colum.edu), used under CC BY.
* https://creativecommons.org/licenses/by/4.0/
* "[Your Game Title]" is licensed under
* [license] by [Your name here].
*/
namespace MegaByteBakery
{
class Program
{
static void Main()
{
Bakery bakery = new Bakery();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment