102 lines
3.1 KiB
C#
102 lines
3.1 KiB
C#
namespace ordini_ristorante;
|
|
|
|
class Program {
|
|
static void Main(string[] args) {
|
|
Console.Clear();
|
|
Ristorante ristorante = new();
|
|
int scelta = -1;
|
|
do {
|
|
Console.WriteLine("Inserire un'opzione:");
|
|
Console.WriteLine("1. Crea piatto");
|
|
Console.WriteLine("2. Visualizza menù");
|
|
Console.WriteLine("3. Crea ordine");
|
|
Console.WriteLine("4. Annulla ordine");
|
|
Console.WriteLine("5. Paga ordine");
|
|
Console.WriteLine("6. Visualizza ordine");
|
|
Console.WriteLine("0. Esci");
|
|
Console.Write("Scelta: ");
|
|
try {
|
|
scelta = Convert.ToInt32(Console.ReadLine());
|
|
switch (scelta) {
|
|
case 0:
|
|
break;
|
|
case 1:
|
|
AggiungiPiatto(ristorante);
|
|
Console.WriteLine("Piatto aggiunto con successo");
|
|
Pausa();
|
|
break;
|
|
case 2:
|
|
StampaMenu(ristorante);
|
|
Pausa();
|
|
break;
|
|
case 3:
|
|
Pausa();
|
|
break;
|
|
case 4:
|
|
Pausa();
|
|
break;
|
|
case 5:
|
|
Pausa();
|
|
break;
|
|
case 6:
|
|
Pausa();
|
|
break;
|
|
default:
|
|
Console.WriteLine("Opzione non valida.");
|
|
Pausa();
|
|
break;
|
|
}
|
|
}
|
|
catch (FormatException) {
|
|
Console.WriteLine("Opzione non valida.");
|
|
Pausa();
|
|
}
|
|
}
|
|
while (scelta != 0);
|
|
}
|
|
static void Pausa() {
|
|
Console.WriteLine("Premere un tasto per continuare. . .");
|
|
Console.ReadKey();
|
|
}
|
|
|
|
static void AggiungiPiatto(Ristorante p_ristorante) {
|
|
string nome;
|
|
string descrizione;
|
|
float prezzo = -1;
|
|
|
|
Console.Write("Nome del piatto: ");
|
|
nome = Console.ReadLine();
|
|
|
|
Console.Write("Descrizione del piatto: ");
|
|
descrizione = Console.ReadLine();
|
|
|
|
do {
|
|
try {
|
|
Console.Write("Inserire il prezzo: ");
|
|
prezzo = (float)Convert.ToDouble(Console.ReadLine());
|
|
if (prezzo < 0) {
|
|
Console.WriteLine("Prezzo non valido.");
|
|
Pausa();
|
|
}
|
|
}
|
|
catch (FormatException) {
|
|
Console.WriteLine("Prezzo non valido.");
|
|
Pausa();
|
|
}
|
|
}
|
|
while (prezzo < 0);
|
|
|
|
p_ristorante.AggiungiPiatto(new Piatto(nome, descrizione, prezzo));
|
|
}
|
|
|
|
static void StampaMenu(Ristorante p_ristorante) {
|
|
int i = 0;
|
|
foreach (Piatto p in p_ristorante.GetMenu()) {
|
|
Console.WriteLine($"Piatto {i + 1}:");
|
|
p.StampaPiatto();
|
|
Console.WriteLine();
|
|
i++;
|
|
}
|
|
}
|
|
}
|