Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.91 KB | None | 0 0
  1. using System;
  2.  
  3. namespace tane_superior
  4. {
  5.     public class Item
  6.     {
  7.         public string Name
  8.         {
  9.             get;
  10.         }
  11.         public double Price
  12.         {
  13.             get;
  14.         }
  15.         public int Quantity
  16.         {
  17.             get;
  18.         }
  19.  
  20.         public Item(string itemName, double itemPrice, int numPurchased)
  21.         {
  22.             Name = itemName;
  23.             Price = itemPrice;
  24.             Quantity = numPurchased;
  25.         }
  26.  
  27.         public override string ToString()
  28.         {
  29.             return $"{Name}\t\t{Price:C}\t\t{Quantity}\t\t{Price * Quantity:C}";
  30.         }
  31.     }
  32.  
  33.     public class ShoppingCart
  34.     {
  35.         private int itemCount;
  36.         private double totalPrice;
  37.         private int capacity;
  38.         private Item[] cart;
  39.  
  40.         public ShoppingCart()
  41.         {
  42.             capacity = 5;
  43.             itemCount = 0;
  44.             totalPrice = 0.0;
  45.             cart = new Item[capacity];
  46.         }
  47.  
  48.         public void AddToCart(string itemName, double price, int quantity)
  49.         {
  50.             if (itemCount + 1 <= capacity)
  51.             {
  52.                 cart[itemCount] = new Item(itemName, price, quantity);
  53.                 totalPrice += price;
  54.                 itemCount += 1;
  55.             }
  56.             else
  57.             {
  58.                 IncreaseSize();
  59.             }
  60.         }
  61.  
  62.         private void IncreaseSize()
  63.         {
  64.             capacity += 3;
  65.         }
  66.  
  67.         public override string ToString()
  68.         {
  69.             string contents = "\nShopping Cart\n";
  70.             contents += "\nItem\t\tUnit Price\tQuantity\tTotal\n";
  71.             for (int i = 0; i < itemCount; i++)
  72.             {
  73.                 contents += cart[i] + "\n";
  74.             }
  75.             contents += $"\nTotal Price: {totalPrice:C}\n";
  76.             return contents;
  77.         }
  78.     }
  79.  
  80.     internal class Nigger
  81.     {
  82.         public static int IntReader()
  83.         {
  84.             bool success = (bool)default;
  85.             int number = (int)default;
  86.             while (!success)
  87.             {
  88.                 if (int.TryParse(Console.ReadLine(), out number))
  89.                 {
  90.                     success = true;
  91.                 }
  92.                 else Console.WriteLine("было введено неправильное число, выполните ввод заново");
  93.             }
  94.             return number;
  95.         }
  96.  
  97.         public static bool CycleBreaker()
  98.         {
  99.             int response = (int)default;
  100.             bool conclusion = (bool)default;
  101.             bool success = (bool)default;
  102.             while (!success)
  103.             {
  104.                 switch (response)
  105.                 {
  106.                     case 1:
  107.  
  108.                 }
  109.             }
  110.             return conclusion;
  111.         }
  112.     }
  113.  
  114.     internal class Program
  115.         {
  116.             private static void Main(string[] args)
  117.             {
  118.             }
  119.         }
  120.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement