Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.47 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Automat
  8. {
  9.     class Program
  10.     {
  11.         public static float givingChange(float priceOfPotion, float userMoney)
  12.         {
  13.             float rest = 0;
  14.             rest = userMoney - priceOfPotion;
  15.             return rest;
  16.         }
  17.         static void Main()
  18.         {
  19.             Fanta newFanta = new Fanta();
  20.             CocaCola newCocaCola = new CocaCola();
  21.             Sprite newSprite = new Sprite();
  22.             while (true)
  23.             {
  24.                 Console.WriteLine("Witaj! Wybierz napój, który chcesz kupić!");
  25.                 Console.WriteLine("Wcisnij 1 jeśli ma być to Fanta.");
  26.                 Console.WriteLine("Wcisnij 2 jeśli ma być to CocaCola.");
  27.                 Console.WriteLine("Wciśnij 3 jeśli ma być to Sprite.");
  28.                 Console.WriteLine("Wciśnij 4, by zakończyć!");
  29.                 int choice = int.Parse(Console.ReadLine());
  30.                 Console.WriteLine();
  31.                 while (true)
  32.                 {
  33.                     if (choice == 1)
  34.                     {
  35.                         Console.Write("Wybrano Fantę. Wrzuć monetę: ");
  36.                         float userMoney = float.Parse(Console.ReadLine());
  37.                         Console.WriteLine("Wrzucono: " + userMoney + ".");
  38.                         Console.WriteLine();
  39.                         if (newFanta.CountOfPotion > 0)
  40.                         {
  41.                             if (userMoney >= newFanta.Price)
  42.                             {
  43.                                 Console.WriteLine("Odbierz produkt!");
  44.                                 newFanta.CountOfPotion -= 1;
  45.                                 Console.WriteLine();
  46.                                 if (userMoney > newFanta.Price)
  47.                                 {
  48.                                     Console.WriteLine("Reszta to: "+givingChange(newFanta.Price, userMoney)+"zł.");
  49.                                     Console.WriteLine();
  50.                                     break;
  51.                                 }
  52.                                 else
  53.                                 {
  54.                                     break;
  55.                                 }
  56.                             }
  57.                             else
  58.                             {
  59.                                 Console.WriteLine("Wrzucono za mało pieniędzy!");
  60.                                 Console.WriteLine();
  61.                                 break;
  62.                             }
  63.                         }
  64.                         else
  65.                         {
  66.                             Console.WriteLine("Brak produktu.");
  67.                             Console.WriteLine("Wydaje reszte: "+givingChange(newFanta.Price, userMoney)+"zł.");
  68.                             Console.WriteLine();
  69.                             break;
  70.                         }
  71.                     }
  72.                     else if (choice == 2)
  73.                     {
  74.                         Console.Write("Wybrano CocaCole. Wrzuć monetę: ");
  75.                         float userMoney = float.Parse(Console.ReadLine());
  76.                         Console.WriteLine("Wrzucono: " + userMoney + ".");
  77.                         Console.WriteLine();
  78.                         if (newCocaCola.CountOfPotion > 0)
  79.                         {
  80.                             if (userMoney >= newCocaCola.Price)
  81.                             {
  82.                                 Console.WriteLine("Odbierz produkt!");
  83.                                 newCocaCola.CountOfPotion -= 1;
  84.                                 Console.WriteLine();
  85.                                 if (userMoney > newCocaCola.Price)
  86.                                 {
  87.                                     Console.WriteLine("Reszta to: "+givingChange(newCocaCola.Price, userMoney)+"zł.");
  88.                                     Console.WriteLine();
  89.                                     break;
  90.                                 }
  91.                                 else
  92.                                 {
  93.                                     break;
  94.                                 }
  95.                             }
  96.                             else
  97.                             {
  98.                                 Console.WriteLine("Wrzucono za mało pieniędzy!");
  99.                                 Console.WriteLine();
  100.                                 break;
  101.                             }
  102.                         }
  103.                         else
  104.                         {
  105.                             Console.WriteLine("Brak produktu.");
  106.                             Console.WriteLine("Wydaje reszte: "+givingChange(newSprite.Price, userMoney)+"zł.");
  107.                             Console.WriteLine();
  108.                             break;
  109.                         }
  110.                     }
  111.                     else if (choice == 3)
  112.                     {
  113.                         Console.Write("Wybrano Sprite. Wrzuć monetę: ");
  114.                         float userMoney = float.Parse(Console.ReadLine());
  115.                         Console.WriteLine("Wrzucono: " + userMoney + ".");
  116.                         Console.WriteLine();
  117.                         if (newSprite.CountOfPotion > 0)
  118.                         {
  119.                             if (userMoney >= newSprite.Price)
  120.                             {
  121.                                 Console.WriteLine("Odbierz produkt!");
  122.                                 newSprite.CountOfPotion -= 1;
  123.                                 Console.WriteLine();
  124.  
  125.                                 if (userMoney > newSprite.Price)
  126.                                 {
  127.                                     Console.WriteLine("Reszta to: "+givingChange(newSprite.Price, userMoney)+"zł.");
  128.                                     Console.WriteLine();
  129.                                     break;
  130.                                 }
  131.                                 else
  132.                                 {
  133.                                     break;
  134.                                 }
  135.                             }
  136.                             else
  137.                             {
  138.                                 Console.WriteLine("Wrzucono za mało pieniędzy!");
  139.                                 Console.WriteLine();
  140.                                 break;
  141.                             }
  142.                         }
  143.                         else
  144.                         {
  145.                             Console.WriteLine("Brak produktu.");
  146.                             Console.WriteLine("Wydaje reszte: "+givingChange(newSprite.Price, userMoney)+"zł.");
  147.                             Console.WriteLine();
  148.                             break;
  149.                         }
  150.                     }
  151.                     else if (choice == 4)
  152.                     {
  153.                         System.Environment.Exit(1);
  154.                     }
  155.                     else
  156.                     {
  157.                         Console.WriteLine("Nie ma takiego wyboru.");
  158.                         Console.WriteLine();
  159.                         break;
  160.                     }
  161.                 }
  162.             }
  163.         }
  164.     }
  165.  
  166.     class Fanta
  167.     {
  168.         int countOfPotion;
  169.         public int CountOfPotion
  170.         {
  171.             get { return countOfPotion; }
  172.             set { countOfPotion = value; }
  173.         }
  174.         float price;
  175.         public float Price
  176.         {
  177.             get { return price; }
  178.             set { price = value; }
  179.         }
  180.  
  181.         public Fanta()
  182.         {
  183.             countOfPotion = 3;
  184.             price = 3.0f;
  185.         }
  186.     }
  187.     class CocaCola
  188.     {
  189.         int countOfPotion;
  190.         public int CountOfPotion
  191.         {
  192.             get { return countOfPotion; }
  193.             set { countOfPotion = value; }
  194.         }
  195.         float price;
  196.         public float Price
  197.         {
  198.             get { return price; }
  199.             set { price = value; }
  200.         }
  201.         public CocaCola()
  202.         {
  203.             countOfPotion = 3;
  204.             price = 2.50f;
  205.         }
  206.     }
  207.     class Sprite
  208.     {
  209.         int countOfPotion;
  210.         public int CountOfPotion
  211.         {
  212.             get { return countOfPotion; }
  213.             set { countOfPotion = value; }
  214.         }
  215.         float price;
  216.         public float Price
  217.         {
  218.             get { return price; }
  219.             set { price = value; }
  220.         }
  221.         public Sprite()
  222.         {
  223.             countOfPotion = 3;
  224.             price = 3.50f;
  225.         }
  226.     }
  227. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement