Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace RestaurantAssignment
- {
- public class Stock
- {
- public List<DrinkItem> Drinks { get; set; }
- public List<FoodItem> Foods { get; set; }
- public Stock()
- {
- Drinks = new List<DrinkItem>();
- Foods = new List<FoodItem>();
- }
- public List<string> GetDrinkNames()
- {
- List<string> drinks = new List<string>();
- foreach (var item in Drinks)
- {
- var name = item.Name;
- // If the item is alcoholic, add alcoholic volume to item name
- if (item.IsAlcoholic())
- name = $"{name} ({item.GetAlcoholicVolume()}%)";
- // name = name + " (" + item.GetAlcoholicVolume() + "%)";
- drinks.Add(name);
- }
- return drinks;
- }
- public List<string> GetFoodNames()
- {
- List<string> foods = new List<string>();
- foreach (var item in Foods)
- {
- foods.Add(item.Name);
- }
- return foods;
- }
- public List<DrinkItem> GetAlcoholicDrinks()
- {
- List<DrinkItem> alcholicDrinks = new List<DrinkItem>();
- foreach (var item in Drinks)
- {
- if (item.IsAlcoholic())
- alcholicDrinks.Add(item);
- }
- return alcholicDrinks;
- }
- public List<string> GetAlcoholicDrinkNames()
- {
- List<string> alcholicDrinkNames = new List<string>();
- foreach (var item in Drinks)
- {
- if (item.IsAlcoholic())
- alcholicDrinkNames.Add(item.Name);
- }
- return alcholicDrinkNames;
- }
- // Assign total cost to all items on order
- public double TotalCost()
- {
- double runningTotal = 0;
- foreach (var drink in Drinks)
- {
- runningTotal += drink.GetCost();
- }
- foreach (var food in Foods)
- {
- runningTotal += food.GetCost();
- }
- return runningTotal;
- }
- // User creates new food item and assigns the appropriate number of servings
- public void AddFoodItem()
- {
- FoodItem food = new FoodItem();
- AddItem(food);
- Console.WriteLine("Add number of servings");
- Console.Write("> ");
- var servings = Console.ReadLine();
- food.SetNumberServed(Convert.ToInt32(servings));
- Foods.Add(food);
- using (StreamWriter sw = new StreamWriter("Drink_menu.txt", true))
- {
- sw.WriteLine(outputDrink);
- }
- }
- // User creates new drink and adds alcoholic volume
- public void AddDrinkItem()
- {
- DrinkItem drink = new DrinkItem();
- AddItem(drink);
- Console.WriteLine("Enter alcoholic volume");
- Console.Write("> ");
- var alcoholic = Console.ReadLine();
- drink.SetAlcoholicVolume(Convert.ToDouble(alcoholic));
- Drinks.Add(drink);
- }
- // User inputs name, description and price. This is then assigned to the item
- public void AddItem(Item item)
- {
- Console.WriteLine("Adding new item...");
- Console.WriteLine("Enter new item name");
- Console.Write("> ");
- item.Name = Console.ReadLine();
- Console.WriteLine("Enter new item description");
- Console.Write("> ");
- item.Description = Console.ReadLine();
- Console.WriteLine("Enter new item price");
- Console.Write("> ");
- item.SetCost(Convert.ToDouble(Console.ReadLine()));
- }
- }
- public class Item
- {
- public string Name;
- public string Description;
- private double cost;
- public Item()
- {
- }
- public double GetCost()
- {
- return cost;
- }
- // SetCost ensures a valid cost is set
- public void SetCost(double newCost)
- {
- // Turnary statement, if new cost is less than or equal to 0
- // Set cost to 0, else set the cost to new cost
- cost = (newCost <= 0) ? 0 : newCost;
- }
- }
- public class FoodItem : Item
- {
- private int numberServed;
- public int GetNumberServed()
- {
- return numberServed;
- }
- public void SetNumberServed(int servings)
- {
- // Check that servings does not exceed the maximum.
- if (servings < 0 || servings > 4)
- {
- return;
- }
- numberServed = servings;
- }
- public FoodItem(string name)
- {
- Name = name;
- }
- public FoodItem()
- {
- }
- }
- // 1. AlcoholicVolume Property
- // 2. Getter and Setter for AlcoholicVolume
- // 3. Add validation to the AlcoholicVolume Setter
- // 4. Add a Constructor for Drink which takes a name
- // 5. Add IsAlcoholic() method, returning true if
- // AlcoholicVolume is > 0.
- public class DrinkItem : Item
- {
- private double AlcoholicVolume;
- public double GetAlcoholicVolume()
- {
- return AlcoholicVolume;
- }
- public void SetAlcoholicVolume(double volume)
- {
- // Check if level of alcohol is < 0
- if (AlcoholicVolume < 0)
- {
- return;
- }
- AlcoholicVolume = volume;
- }
- public DrinkItem(string name)
- {
- Name = name;
- }
- public DrinkItem()
- {
- }
- public bool IsAlcoholic()
- {
- // Checks if alcoholic volume is > 0, if it is
- // return true
- return AlcoholicVolume > 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement