Advertisement
Guest User

Książka telefoniczna

a guest
Jul 17th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.07 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. using System.Threading;
  7.  
  8.  
  9. namespace Ksiazka_telefoniczna
  10. {
  11.     class Program
  12.     {
  13.         public static void Sleep(int milisekundy)
  14.         {
  15.  
  16.         }
  17.  
  18.         static int Menu_glowne_wybor()
  19.         {
  20.             Console.Clear();
  21.             Console.WriteLine("Witaj w programie: Książka telefoniczna!");
  22.             Console.WriteLine("[1] Otwórz książke.");
  23.             Console.WriteLine("[2] Załóż nową książke.");
  24.             Console.WriteLine("[3] Dodaj nową osobe.");
  25.             Console.WriteLine("[4] Wyjdź z programu.");
  26.             Console.Write("Wybierz: ");
  27.             return int.Parse(Console.ReadLine());
  28.         }
  29.         static void Main(string[] args)
  30.         {
  31.             List<string> lista = new List<string>();
  32.             bool koniec=true;
  33.             bool czyKsiazkaUtworzona=false;
  34.             string nazwaKsiazki="ksiazka";
  35.             while (koniec)
  36.             {
  37.                 int wybor = Menu_glowne_wybor();
  38.                 switch (wybor)
  39.                 {
  40.                     case 1:
  41.                         {
  42.                             Console.Clear();
  43.                             if (czyKsiazkaUtworzona == true) {
  44.                                 int numer=0;
  45.                                 Console.Write(nazwaKsiazki);
  46.                                 Console.WriteLine(":");
  47.                                 Console.WriteLine();
  48.                                 string pole = string.Empty;
  49.                                 foreach (string tekst in lista)
  50.                                 {
  51.                                     if(numer==3)
  52.                                     {
  53.                                         Console.WriteLine();
  54.                                         numer = 0;
  55.                                     }
  56.                                     numer++;
  57.                                     Console.Write(numer);
  58.                                     Console.Write(".");
  59.                                     Console.WriteLine(tekst);
  60.                                 }
  61.                                 Console.Write("Wciśnij dowolny klawisz aby kontynuować...");
  62.                                 Console.ReadKey();
  63.                                 break;
  64.                             }
  65.                             else {
  66.                                 Console.WriteLine("Nie utworzyłeś jeszcze książki!");
  67.                                 Console.WriteLine("Zostaniesz przekierowany do menu głównego.");
  68.                                 Thread.Sleep(2000);
  69.                                 break;
  70.                             }
  71.                         }
  72.                     case 2:
  73.                         {
  74.                             Console.Clear();
  75.                             if (czyKsiazkaUtworzona == true)
  76.                             {
  77.                                 Console.WriteLine("Utworzyles już wcześniej książke, czy chcesz ją utworzyć jeszcze raz?");
  78.                                 Console.Write("Wybierz 1(tak) lub 2(nie): ");
  79.                                 int CzyTworzycJeszczeRaz = int.Parse(Console.ReadLine());
  80.                                 switch(CzyTworzycJeszczeRaz)
  81.                                 {
  82.                                     case 1:
  83.                                         {
  84.                                             Console.Clear();
  85.                                             lista = new List<string>(); // reset starej ksiazki
  86.                                             Console.Write("Podaj nazwę książki: ");
  87.                                             nazwaKsiazki = Console.ReadLine();
  88.                                             czyKsiazkaUtworzona = true;
  89.                                             Console.WriteLine("Pomyślnie utworzono książke telefoniczną.");
  90.                                             Thread.Sleep(2000);
  91.                                             break;
  92.                                         }
  93.                                     case 2:
  94.                                         {
  95.                                             Console.Clear();
  96.                                             break;
  97.                                         }
  98.                                     default:
  99.                                         {
  100.                                             Console.Clear();
  101.                                             Console.WriteLine("Zła odpowiedź!");
  102.                                             Console.WriteLine("Zostaniesz przekierowany do menu głównego.");
  103.                                             Thread.Sleep(2000);
  104.                                             break;
  105.                                         }
  106.                                 }
  107.                             }
  108.                             else
  109.                             {
  110.                                 Console.Clear();
  111.                                 Console.Write("Podaj nazwę książki: ");
  112.                                 nazwaKsiazki = Console.ReadLine();
  113.                                 czyKsiazkaUtworzona = true;
  114.                                 Console.WriteLine("Pomyślnie utworzono książke telefoniczną.");
  115.                                 Thread.Sleep(2000);
  116.                                 break;
  117.                             }
  118.                             break;
  119.                         }
  120.                     case 3:
  121.                         {
  122.                             string imie;
  123.                             string nazwisko;
  124.                             string numer_telefonu;
  125.                             Console.Clear();
  126.                             if (czyKsiazkaUtworzona == true)
  127.                             {
  128.                                 Console.Write("Podaj imie: ");
  129.                                 imie = Console.ReadLine();
  130.                                 lista.Add(imie);
  131.  
  132.                                 Console.Write("Podaj nazwisko: ");
  133.                                 nazwisko = Console.ReadLine();
  134.                                 lista.Add(nazwisko);
  135.                                 do
  136.                                 {
  137.                                     Console.Write("Podaj numer: ");
  138.                                     numer_telefonu = Console.ReadLine();
  139.                                     if (numer_telefonu.Length != 9)
  140.                                     {
  141.                                         Console.WriteLine();
  142.                                         Console.WriteLine("Wprowadź prawidłowy numer telefonu!");
  143.                                         Thread.Sleep(2000);
  144.                                         Console.Clear();
  145.                                     }
  146.                                 } while (numer_telefonu.Length != 9);
  147.                                 lista.Add(numer_telefonu);
  148.                                 Console.WriteLine("Pomyslnie zapisano osobe");
  149.                                 Thread.Sleep(2000);
  150.                             }
  151.                             else
  152.                             {
  153.                                 Console.WriteLine("Nie utworzyłeś jeszcze książki!");
  154.                                 Console.WriteLine("Zostaniesz przekierowany do menu głównego.");
  155.                                 Thread.Sleep(2000);
  156.                                 break;
  157.                             }
  158.                             break;
  159.                         }
  160.                     case 4:
  161.                         {
  162.                             koniec = false;
  163.                             break;
  164.                         }
  165.                     default:
  166.                         {
  167.                             Console.Clear();
  168.                             Console.WriteLine("Zła odpowiedź!");
  169.                             Console.WriteLine("Zostaniesz przekierowany do menu głównego.");
  170.                             Thread.Sleep(2000);
  171.                             break;
  172.                         }
  173.                 }
  174.             }
  175.         }
  176.     }
  177.  
  178. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement