Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.15 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Text;
  5.  
  6. namespace ConsoleApp1
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. String path = @"C:\users\public\samochody.txt";
  13.  
  14. Console.WriteLine("Ile samochodow dodac?: ");
  15.  
  16.  
  17. List<Samochod> listaSamochodow = new List<Samochod>();
  18.  
  19. int wybor = 0;
  20.  
  21. do
  22. {
  23. Console.WriteLine("MENU");
  24. Console.WriteLine("1. Dodaj auto:");
  25. Console.WriteLine("2. Wyświetl liste");
  26. Console.WriteLine("3. Wczytaj auta z pliku");
  27. Console.WriteLine("4. Zapisz liste do pliku");
  28. Console.WriteLine("5. Wyczysc liste");
  29. Console.WriteLine("6. Wyjdź");
  30.  
  31. wybor = Int32.Parse(Console.ReadLine());
  32.  
  33. switch(wybor)
  34. {
  35. case 1:
  36. {
  37. listaSamochodow.Add(new Samochod());
  38. break;
  39. }
  40. case 2:
  41. {
  42. foreach(Samochod autko in listaSamochodow)
  43. {
  44. autko.WyswietlInfo();
  45. }
  46. break;
  47. }
  48. case 3:
  49. {
  50. string[] lines = File.ReadAllLines(path, Encoding.UTF8);
  51. string[] dane = new string[3];
  52. int i = 0;
  53. foreach (string line in lines)
  54. {
  55. dane[i] = line;
  56. i++;
  57. if (i == 3)
  58. {
  59. i = 0;
  60. listaSamochodow.Add(new Samochod(dane[0], dane[1], int.Parse(dane[2])));
  61. }
  62. }
  63. break;
  64. }
  65. case 4:
  66. {
  67. foreach (Samochod s1 in listaSamochodow)
  68. {
  69. File.AppendAllText(path, s1.marka);
  70. File.AppendAllText(path, Environment.NewLine);
  71. File.AppendAllText(path, s1.model);
  72. File.AppendAllText(path, Environment.NewLine);
  73. File.AppendAllText(path, s1.predkosc.ToString());
  74. File.AppendAllText(path, Environment.NewLine);
  75. }
  76. break;
  77. }
  78. case 5:
  79. {
  80. listaSamochodow.Clear();
  81. break;
  82. }
  83. }
  84. } while (wybor != 6);
  85.  
  86.  
  87. Console.ReadKey();
  88. }
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement