Inserisci prenotazione
This commit is contained in:
parent
7a145377b9
commit
f9184fea2c
16
Cliente.cs
16
Cliente.cs
@ -60,18 +60,14 @@ class Cliente {
|
|||||||
public void InserisciPrenotazione(string p_periodo, string p_giorniPrenotati, string p_numeroPersone) {
|
public void InserisciPrenotazione(string p_periodo, string p_giorniPrenotati, string p_numeroPersone) {
|
||||||
bool isPrenotazioneEsistente = true;
|
bool isPrenotazioneEsistente = true;
|
||||||
int i;
|
int i;
|
||||||
if (this.prenotazioni.Length > 10) {
|
|
||||||
throw new Exception("Errore: sono consentite solo 10 prenotazioni per cliente");
|
//trova la prima cella disponibile
|
||||||
}
|
for (i = 0; i < this.prenotazioni.Length && isPrenotazioneEsistente; i++) {
|
||||||
else {
|
if (this.prenotazioni[i] == null) {
|
||||||
//trova la prima cella disponibile
|
isPrenotazioneEsistente = false;
|
||||||
for (i = 0; i < this.prenotazioni.Length && isPrenotazioneEsistente; i++) {
|
|
||||||
if (this.prenotazioni[i] == null) {
|
|
||||||
isPrenotazioneEsistente = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
this.prenotazioni[i] = new Prenotazione(p_periodo, p_giorniPrenotati, p_numeroPersone, this.GetCodiceFiscale());
|
|
||||||
}
|
}
|
||||||
|
this.prenotazioni[i] = isPrenotazioneEsistente ? throw new Exception("Errore: sono consentite solo 10 prenotazioni per cliente") : new Prenotazione(p_periodo, p_giorniPrenotati, p_numeroPersone, this.GetCodiceFiscale());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CancellaPrenotazione(string p_UUID) {
|
public void CancellaPrenotazione(string p_UUID) {
|
||||||
|
|||||||
@ -9,10 +9,10 @@ class Prenotazione {
|
|||||||
string codiceFiscalePrenotante;
|
string codiceFiscalePrenotante;
|
||||||
|
|
||||||
public Prenotazione(string p_periodo, string p_giorniPrenotati, string p_numeroPersone, string p_codiceFiscalePrenotante) {
|
public Prenotazione(string p_periodo, string p_giorniPrenotati, string p_numeroPersone, string p_codiceFiscalePrenotante) {
|
||||||
this.UUID = this.SetUUID();
|
this.SetUUID();
|
||||||
this.periodo = p_periodo;
|
this.periodo = p_periodo;
|
||||||
this.giorniPrenotati = p_giorniPrenotati;
|
this.giorniPrenotati = p_giorniPrenotati;
|
||||||
this.costo = this.SetCosto();
|
this.SetCosto();
|
||||||
this.numeroPersone = p_numeroPersone;
|
this.numeroPersone = p_numeroPersone;
|
||||||
this.codiceFiscalePrenotante = p_codiceFiscalePrenotante;
|
this.codiceFiscalePrenotante = p_codiceFiscalePrenotante;
|
||||||
}
|
}
|
||||||
@ -41,9 +41,15 @@ class Prenotazione {
|
|||||||
return this.codiceFiscalePrenotante;
|
return this.codiceFiscalePrenotante;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetUUID(string p_UUID) {
|
public void SetUUID() {
|
||||||
this.UUID = p_UUID;
|
const int LUNGHEZZA = 16;
|
||||||
//è un calcolo particolare, va fatto meglio
|
Random random = new Random();
|
||||||
|
const string caratteri = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||||
|
char[] risultato = new char[LUNGHEZZA];
|
||||||
|
for (int i = 0; i < LUNGHEZZA; i++) {
|
||||||
|
risultato[i] = caratteri[random.Next(caratteri.Length)];
|
||||||
|
}
|
||||||
|
this.UUID = string.Join("", risultato);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetPeriodo(string p_periodo) {
|
public void SetPeriodo(string p_periodo) {
|
||||||
@ -54,9 +60,9 @@ class Prenotazione {
|
|||||||
this.giorniPrenotati = p_giorniPrenotati;
|
this.giorniPrenotati = p_giorniPrenotati;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetCosto(string p_costo) {
|
public void SetCosto() {
|
||||||
this.costo = p_costo;
|
Random random = new Random();
|
||||||
//è un calcolo particolare, va fatto meglio
|
this.costo = Convert.ToString(random.Next());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetNumeroPersone(string p_numeroPersone) {
|
public void SetNumeroPersone(string p_numeroPersone) {
|
||||||
|
|||||||
81
Program.cs
81
Program.cs
@ -1,4 +1,6 @@
|
|||||||
namespace agenzia_viaggi;
|
using System.Linq.Expressions;
|
||||||
|
|
||||||
|
namespace agenzia_viaggi;
|
||||||
|
|
||||||
class Program {
|
class Program {
|
||||||
static void Main(string[] args) {
|
static void Main(string[] args) {
|
||||||
@ -111,6 +113,75 @@ class Program {
|
|||||||
Pausa();
|
Pausa();
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
|
string[] periodi = ["primavera", "estate", "autunno", "inverno"];
|
||||||
|
int giorniPrenotati = 0, numeroPersone = 0;
|
||||||
|
do {
|
||||||
|
Console.WriteLine("Inserire la prenotazione di quale cliente? ");
|
||||||
|
try {
|
||||||
|
input = Convert.ToInt32(Console.ReadLine());
|
||||||
|
}
|
||||||
|
catch (FormatException) {
|
||||||
|
Console.WriteLine("Opzione non valida");
|
||||||
|
Pausa();
|
||||||
|
}
|
||||||
|
if (input <= 0 || input > numeroClienti) {
|
||||||
|
Console.WriteLine("Opzione non valida");
|
||||||
|
Pausa();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (input <= 0 || input > numeroClienti);
|
||||||
|
|
||||||
|
do {
|
||||||
|
Console.WriteLine("Quale periodo dell'anno scegliere?");
|
||||||
|
Console.WriteLine("1. Primavera");
|
||||||
|
Console.WriteLine("2. Estate");
|
||||||
|
Console.WriteLine("3. Autunno");
|
||||||
|
Console.WriteLine("4. Inverno");
|
||||||
|
Console.Write("Scelta: ");
|
||||||
|
try {
|
||||||
|
scelta = Convert.ToInt32(Console.ReadLine());
|
||||||
|
}
|
||||||
|
catch (FormatException) {
|
||||||
|
Console.WriteLine("Opzione non valida");
|
||||||
|
Pausa();
|
||||||
|
}
|
||||||
|
if (scelta < 1 || scelta > 4) {
|
||||||
|
|
||||||
|
}
|
||||||
|
} while (scelta < 1 || scelta > 4);
|
||||||
|
|
||||||
|
do {
|
||||||
|
Console.Write("Per quanti giorni prenotare?");
|
||||||
|
try {
|
||||||
|
giorniPrenotati = Convert.ToInt32(Console.ReadLine());
|
||||||
|
}
|
||||||
|
catch (FormatException) {
|
||||||
|
Console.WriteLine("Numero non valido");
|
||||||
|
}
|
||||||
|
if (giorniPrenotati <= 0) {
|
||||||
|
Console.WriteLine("Errore: impossibile prenotare per meno di un giorno.");
|
||||||
|
Pausa();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (giorniPrenotati <= 0);
|
||||||
|
|
||||||
|
do {
|
||||||
|
Console.Write("Per quante persone prenotare?");
|
||||||
|
try {
|
||||||
|
numeroPersone = Convert.ToInt32(Console.ReadLine());
|
||||||
|
}
|
||||||
|
catch (FormatException) {
|
||||||
|
Console.WriteLine("Numero non valido");
|
||||||
|
}
|
||||||
|
if (numeroPersone <= 0) {
|
||||||
|
Console.WriteLine("Errore: impossibile prenotare per meno di una persona.");
|
||||||
|
Pausa();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (numeroPersone <= 0);
|
||||||
|
|
||||||
|
clienti[input].InserisciPrenotazione(periodi[scelta], Convert.ToString(giorniPrenotati), Convert.ToString(numeroPersone));
|
||||||
|
|
||||||
Pausa();
|
Pausa();
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
@ -138,6 +209,7 @@ class Program {
|
|||||||
static Cliente CreaCliente() {
|
static Cliente CreaCliente() {
|
||||||
string nome, cognome, codiceFiscale;
|
string nome, cognome, codiceFiscale;
|
||||||
int eta = 0, prenotazioni = 0;
|
int eta = 0, prenotazioni = 0;
|
||||||
|
const int MAX_PRENOTAZIONI = 10;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
Console.Write("Inserire il nome: ");
|
Console.Write("Inserire il nome: ");
|
||||||
@ -198,9 +270,14 @@ class Program {
|
|||||||
Console.WriteLine("Errore: non è possibile inserire un numero di prenotazioni inferiore a 1");
|
Console.WriteLine("Errore: non è possibile inserire un numero di prenotazioni inferiore a 1");
|
||||||
Pausa();
|
Pausa();
|
||||||
}
|
}
|
||||||
|
else if (prenotazioni > MAX_PRENOTAZIONI) {
|
||||||
|
Console.WriteLine($"Errore: sono consentite al massimo {MAX_PRENOTAZIONI} prenotazioni per cliente");
|
||||||
|
Pausa();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
while (prenotazioni <= 0);
|
while (prenotazioni <= 0 && prenotazioni > MAX_PRENOTAZIONI);
|
||||||
|
|
||||||
return new Cliente(nome, cognome, codiceFiscale, Convert.ToString(eta), prenotazioni);
|
return new Cliente(nome, cognome, codiceFiscale, Convert.ToString(eta), prenotazioni);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user