using System.Collections.Generic;
private List<Fruit> items = new List<Fruit>();
public int Capacity { get; set; }
public Basket(int capacity) => (Capacity) = (capacity);
return ItemCount() == Capacity;
public int RemainingCapacity()
return Capacity - ItemCount();
public List<Fruit> GetFruit()
public double ItemsTotalWeight()
foreach (Fruit f in items)
public double ItemsTotalprice()
foreach (Fruit f in items)
public void Remove (string name, string price)
if (Double.TryParse(price, out dPrice))
for (int i = 0; i < items.Count; i++)
if (f.Price == dPrice && f.Name == name)
public enum OrangeSubType
public enum BananaRipeness
public Fruit(string name, FruitColor color, double weight, double price) => (Name, Color, Weight, Price) = (name, color, weight, price);
public string Name { get; set; }
public FruitColor Color { get; set; }
public double Weight { get; set; }
public double Price { get; set; }
public Apple(string name, FruitSize size, FruitColor color, double weight, double price) => (Name, Color, Weight, Price, Size) = (name, color, weight, price, size);
public FruitSize Size { get; set; }
public Watermelon(string name, bool seedless, double weight, double price) => (Name, Color, Weight, Price, Seedless) = (name, FruitColor.Green, weight, price, seedless);
public bool Seedless { get; set; }
public Orange(OrangeSubType subtype, FruitSize size, double weight, double price) => (Name, Color, Weight, Price, SubType) = (subtype.ToString(), FruitColor.Orange, 0.4, price, subtype);
public OrangeSubType SubType { get; set; }
class BlackBerries: Fruit
public BlackBerries(string name, bool isWild, double price) => (Name, Color, Weight, Price, IsWild) = (name, FruitColor.Black, 0.2, price, isWild);
public bool IsWild { get; set; }
public Banana(string name, BananaRipeness ripeness, double price) => (Name, Color, Weight, Price, Ripeness) = (name, FruitColor.Yellow, 0.2, price, ripeness);
public BananaRipeness Ripeness { get; set; }
const int MAXIMUM_FRUIT_COUNT = 10;
private static Basket _basket;
public static void Main(string[] args)
_basket = new Basket(MAXIMUM_FRUIT_COUNT);
string instructions = $"Please select an option below.";
List<string> options = new List<string>
options.Add($"{lineNumber} Add Fruit");
options.Add($"{lineNumber} Remove Fruit");
int optionSelected = getOptions(instructions, options);
else if (optionSelected == 2)
else if (optionSelected == 0)
Console.WriteLine($"Your basket has {_basket.ItemCount()} item(s), weighs {_basket.ItemsTotalWeight()} pounds with the value of ${_basket.ItemsTotalprice()}.");
if (_basket.ItemsTotalprice() > 0)
Console.WriteLine("I will put this on your account and you can pay at the end of the month.");
if (_basket.ItemsTotalWeight() > 20.0)
Console.WriteLine("This basket is heavy, I will have someone bring it to your car.");
Console.WriteLine("Thank you for shopping at ACME!");
Console.WriteLine("Press <Enter> key to exit.");
private static void ShowHeader()
Console.WriteLine($"Welcome to ACME Fruit Imporium!");
bool isEmpty = _basket.IsEmpty();
Console.WriteLine($"Your basket is currently empty. You can have {_basket.Capacity} items in the basket.");
else if (_basket.IsFull())
Console.WriteLine($"Your basket currently full with {_basket.Capacity} items. The price is {_basket.ItemsTotalprice():0.00} and weighs {_basket.ItemsTotalWeight():0.00}");
Console.WriteLine($"Your basket currently has {_basket.ItemCount()} item(s). The price is {_basket.ItemsTotalprice():0.00} and weighs {_basket.ItemsTotalWeight():0.00}");
Console.WriteLine($"Name Price Weight (pounds)");
foreach (Fruit fruit in _basket.GetFruit())
Console.WriteLine($"{fruit.Name, -25}${fruit.Price,-5:0.00}{fruit.Weight,18:0.00}");
private static int getOptions(string instructions, List<string> options)
int optionCount = options.Count;
Console.WriteLine(instructions + "\nSelect the number key, then press <Enter>");
foreach (string line in options)
string key = Console.ReadLine();
if (Int32.TryParse(key, out highlightIndex) && highlightIndex < optionCount && highlightIndex > -1)
Console.WriteLine($"'{key}' is not a valid response. Press <Enter> to continue.");
private static void AddFruit()
string instructions = "Select a fruit to add to your basket, then the quantity.";
List<string> fruits = new List<string>
"1 Large Green Apple - $0.50",
"2 Medium Red Apple - $0.45",
"3 Seedless Watermelon - $4.98",
"4 Seeded Watermelon - $3.28",
"8 Organic Blackberries - $0.30",
"9 Wild Blackberries - $0.10",
"10 Green Banana - $0.10",
"11 Yellow Banana - $0.20",
"12 Brown Banana - $0.10",
int optionSelected = getOptions(instructions, fruits);
bool bAskQuantity = true;
Fruit fruit = new Apple("Apple", FruitSize.Unknown, FruitColor.Unknown, 0.0, 0.0);
fruit = new Apple("Green Apple", FruitSize.Large, FruitColor.Green, 0.40, 0.50);
fruit = new Apple("Red Apple", FruitSize.Medium, FruitColor.Red, 0.30, 0.45);
fruit = new Watermelon("Seedless Watermelon", true, 20.40, 4.98);
fruit = new Watermelon("Seeded Watermelon", false, 22.00, 3.28);
fruit = new Orange(OrangeSubType.Nectarine, FruitSize.Medium, 0.40, 0.25);
fruit = new Orange(OrangeSubType.Orange, FruitSize.Medium, 0.40, 0.35);
fruit = new Orange(OrangeSubType.Tangerine, FruitSize.Small, 0.20, 0.29);
fruit = new BlackBerries("Organic BlackBerry", false, 0.30);
fruit = new BlackBerries("Wild BlackBerry", true, 0.10);
fruit = new Banana("Green Banana", BananaRipeness.Green, 0.10);
fruit = new Banana("Yellow Banana", BananaRipeness.Yellow, 0.20);
fruit = new Banana("Brown Banana", BananaRipeness.Brown, 0.10);
bool isValidResponse = false;
instructions = $"Enter the quantity of {fruit.Name}(s) you want to add. Valid values are 0 to {_basket.RemainingCapacity()}";
Console.WriteLine(instructions);
string lineRead = Console.ReadLine();
if (Int32.TryParse(lineRead, out adding) && adding <= _basket.RemainingCapacity())
for (int j = 0; j < adding; j++)
Console.WriteLine($"'{lineRead}' is not a valid response.");
private static void RemoveFruit()
string instructions = $"Your basket contains the following list of items. Select the item you want to remove.";
List<string> items = new List<string>()
foreach (Fruit fruit in _basket.GetFruit())
items.Add($"{index,2} {fruit.Name,-25} - ${fruit.Price,-5:0.00}");
int removing = getOptions(instructions, items);
string name = items[removing].Substring(3, 25).Trim();
string price = items[removing].Substring(32);
_basket.Remove(name, price);