The Information Systems Department is selling T-shirts. Write an algorithm that Creates an attractive user interface that allows users to select sizes (S, M, L, XL) and quantity. Choose the most appropriate controls. Remember, the fewer keystrokes required of the user the better. Display the selections made by the user with the Process menu option. Include an option to exit the application. Include two more sizes, XSmall and XXLarge. Add statements that process the order by calculating the total cost. Each shirt is $16 except the XSmall and XXLarge; their speciality prices are $20 each Display the total cost of then selection. Include a help option that displays instructions. You can enhance your solution by allowing users to purchase different sizes on the same order.
using System;
using System.Collections.Generic;
namespace App
{
class TShirt {
private string size;
private double cost;
private int quantity;
private double totalCost;
public TShirt() {
}
public TShirt(string size, double cost, int quantity)
{
this.size = size;
this.cost = cost;
this.quantity = quantity;
this.totalCost = cost * quantity;
}
public string Size
{
get { return size; }
set { size = value; }
}
public int Quantity
{
get { return quantity; }
set { quantity = value; }
}
public double Cost
{
get { return cost; }
set { cost = value; }
}
public double TotalCost
{
get { return totalCost; }
set { totalCost = value; }
}
}
class Cart {
private List<TShirt> shirts;
public Cart() {
this.shirts = new List<TShirt>();
}
public void addShirtToCart(TShirt newTShirt)
{
this.shirts.Add(newTShirt);
}
public void DisplayOrder() {
Console.WriteLine(String.Format("{0,-10}{1,-10}{2,-10}{3,-10}", "Size", "Quantity", "Cost","Total cost"));
for (int i = 0; i < this.shirts.Count; i++) {
Console.WriteLine(String.Format("{0,-10}{1,-10}{2,-10:C}{3,-10:C}", this.shirts[i].Size, this.shirts[i].Quantity, this.shirts[i].Cost, this.shirts[i].TotalCost));
}
}
}
class Program
{
static void Main(string[] args)
{
int ch = -1;
Cart myCart = new Cart();
while (ch != 4)
{
Console.WriteLine("1. Process");
Console.WriteLine("2. Display Order");
Console.WriteLine("3. Help");
Console.WriteLine("4. Exit");
Console.Write("Your choice: ");
ch = int.Parse(Console.ReadLine());
switch (ch)
{
case 1:
{
while (ch != 2)
{
Console.WriteLine("1. Add a new T-shirt to the cart");
Console.WriteLine("2. Exit to main menu");
Console.Write("Your choice: ");
ch = int.Parse(Console.ReadLine());
if (ch == 1)
{
int quantity=-1;
Console.Write("Select sizes (S, M, L, XL, XSmall and XXLarge): ");
string size = Console.ReadLine().ToUpper();
if (size == "S" || size == "M" || size == "L" || size == "XL")
{
Console.Write("Enter quantity: ");
quantity = int.Parse(Console.ReadLine());
myCart.addShirtToCart(new TShirt(size,16, quantity));
Console.Write("\nThe T-shirt has been added to the cart.\n");
}
else if (size == "XSmall".ToUpper() || size == "XXLarge".ToUpper())
{
Console.Write("Enter quantity: ");
quantity = int.Parse(Console.ReadLine());
myCart.addShirtToCart(new TShirt(size, 20, quantity));
Console.Write("\nThe T-shirt has been added to the cart.\n");
}
else
{
Console.WriteLine("Wrong size.");
}
}
else if (ch == 2)
{
}
else {
Console.WriteLine("Wrong menu item.");
}
}
}
break;
case 2:
{
myCart.DisplayOrder();
}
break;
case 3:
{
Console.WriteLine("\n1. 'Process' menu item allows to add a new T-shirt to the cart");
Console.WriteLine("2. 'Display Order' menu item allows to display all T-shirts in the cart");
Console.WriteLine("3. 'Exit' menu item allows to close the program\n");
}
break;
case 4:
{
//eixt
}
break;
default:
{
Console.WriteLine("Wrong menu item.");
}
break;
}
}
Console.ReadLine();
}
Comments
Leave a comment