Advertisement
Guest User

bubu

a guest
Dec 12th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.95 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 Supermercato
  8. {
  9. static class Dati
  10. {
  11. static Random r = new Random();
  12.  
  13. static public string GeneraCodice()
  14. {
  15. string a = "#" + r.Next(1, 10001);
  16. return a;
  17. }
  18.  
  19. static public int GeneraNProdotti()
  20. {
  21. return r.Next(1, 11);
  22. }
  23.  
  24. static public double Generaprezzo()
  25. {
  26. int a = r.Next(1, 101);
  27. return Convert.ToDouble(a);
  28. }
  29.  
  30. static public string GeneraNome()
  31. {
  32. string a = "Prodotto " + r.Next(1, 51);
  33. return a;
  34. }
  35.  
  36. static public string LeggiNome()
  37. {
  38. Console.Write("Inserisci nome cassiera: ");
  39. return Console.ReadLine();
  40. }
  41.  
  42. static public string LeggiCognome()
  43. {
  44. Console.Write("Inserisci cognome cassiera: ");
  45. return Console.ReadLine();
  46. }
  47. }
  48. }
  49.  
  50.  
  51.  
  52.  
  53. using System;
  54. using System.Collections.Generic;
  55. using System.Linq;
  56. using System.Text;
  57. using System.Threading.Tasks;
  58.  
  59. namespace Supermercato
  60. {
  61. class Cassiera
  62. {
  63. public string Nome { get; set; }
  64. public string Cognome { get; set; }
  65.  
  66. public Cassiera(string n, string c)
  67. {
  68. Nome = n;
  69. Cognome = c;
  70. }
  71. }
  72. }
  73.  
  74.  
  75.  
  76.  
  77.  
  78. using System;
  79. using System.Collections.Generic;
  80. using System.Linq;
  81. using System.Text;
  82. using System.Threading.Tasks;
  83.  
  84. namespace Supermercato
  85. {
  86. class Prodotto
  87. {
  88. public string codice { get; set; }
  89. public string nome { get; set; }
  90. public double prezzo { get; set; }
  91.  
  92. public Prodotto(string c, string n, double p)
  93. {
  94. codice = c;
  95. nome = n;
  96. prezzo = p;
  97. }
  98.  
  99. }
  100. }
  101.  
  102.  
  103.  
  104.  
  105.  
  106. using System;
  107. using System.Collections.Generic;
  108. using System.Linq;
  109. using System.Text;
  110. using System.Threading.Tasks;
  111.  
  112. namespace Supermercato
  113. {
  114. class Cliente
  115. {
  116. Random r = new Random();
  117. List<Prodotto> Prodotti = new List<Prodotto>();
  118.  
  119. public void AddProdotti(Prodotto p)
  120. {
  121. Prodotti.Add(p);
  122. }
  123.  
  124. public void StampaProdotti()
  125. {
  126. double tot = 0;
  127. foreach (Prodotto p in Prodotti)
  128. {
  129. tot += p.prezzo;
  130. Console.WriteLine("Codice: {0}\nNome: {1}\nPrezzo: {2} euro\n", p.codice, p.nome, p.prezzo);
  131. }
  132. Console.WriteLine("Totale: {0}", tot);
  133. }
  134.  
  135. }
  136. }
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143. using System;
  144. using System.Collections.Generic;
  145. using System.Linq;
  146. using System.Text;
  147. using System.Threading.Tasks;
  148.  
  149. namespace Supermercato
  150. {
  151. class Supermercato
  152. {
  153. Queue<Cliente> Clientela=new Queue<Cliente>();
  154. Cassiera cas;
  155.  
  156. public Supermercato(Cassiera c)
  157. {
  158. cas = new Cassiera(c.Nome, c.Cognome);
  159. }
  160.  
  161. public void AggiungiClienti(Cliente c)
  162. {
  163. int k = Dati.GeneraNProdotti();
  164. for (int i = 0; i < k; i++)
  165. {
  166. c.AddProdotti(new Prodotto(Dati.GeneraCodice(), Dati.GeneraNome(), Dati.Generaprezzo()));
  167. }
  168. Clientela.Enqueue(c);
  169. Console.WriteLine("Cliente in coda.");
  170. Console.ReadKey();
  171. }
  172.  
  173. public void Paga()
  174. {
  175. Console.Clear();
  176. if (Clientela.Count == 0)
  177. {
  178. Console.WriteLine("Coda vuota.");
  179. Console.ReadKey();
  180. }
  181. else
  182. {
  183. Cliente c = Clientela.Dequeue();
  184. c.StampaProdotti();
  185. Console.ReadKey();
  186. }
  187. }
  188. }
  189. }
  190.  
  191.  
  192.  
  193.  
  194.  
  195. using System;
  196. using System.Collections.Generic;
  197. using System.Linq;
  198. using System.Text;
  199. using System.Threading.Tasks;
  200.  
  201. namespace Supermercato
  202. {
  203. class Program
  204. {
  205. static void Main(string[] args)
  206. {
  207.  
  208. int scelta = 0;
  209. Console.Clear();
  210. Supermercato S1 = new Supermercato(new Cassiera(Dati.LeggiNome(), Dati.LeggiCognome()));
  211.  
  212. do
  213. {
  214. Console.Clear();
  215. Console.WriteLine("1. Nuovo Cliente");
  216. Console.WriteLine("2. Cassa");
  217. Console.WriteLine("0. Esci");
  218. scelta = Convert.ToInt32(Console.ReadLine());
  219.  
  220. switch (scelta)
  221. {
  222. case 1:
  223. S1.AggiungiClienti(new Cliente());
  224. break;
  225.  
  226. case 2:
  227. S1.Paga();
  228. break;
  229.  
  230. case 0:
  231. break;
  232. }
  233.  
  234. } while (scelta != 0);
  235.  
  236. }
  237. }
  238. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement