diff --git a/Cliente.cs b/Cliente.cs index ceea816..83ec36a 100644 --- a/Cliente.cs +++ b/Cliente.cs @@ -1,123 +1,104 @@ namespace Verifica_incontri; class Cliente { -string nome; - string cognome; - string sesso; - string eta; - string altezza; - string professione; - string[] interessi; - bool isAvailable = true; + string nome; + string cognome; + string sesso; + string eta; + string altezza; + string professione; + string[] interessi; + bool isAvailable = true; - public Cliente(string p_nome, string p_cognome, string p_sesso, string p_eta, string p_altezza, string p_professione, string[] p_interessi) - { - this.nome = p_nome; - this.cognome = p_cognome; - this.sesso = p_sesso; - this.eta = p_eta; - this.altezza = p_altezza; - this.professione = p_professione; - this.interessi = p_interessi; + public Cliente(string p_nome, string p_cognome, string p_sesso, string p_eta, string p_altezza, string p_professione, string[] p_interessi) { + this.nome = p_nome; + this.cognome = p_cognome; + this.sesso = p_sesso; + this.eta = p_eta; + this.altezza = p_altezza; + this.professione = p_professione; + this.interessi = p_interessi; + } + + public string GetNome() { + return this.nome; + } + + public string GetCognome() { + return this.cognome; + } + public string GetSesso() { + return this.sesso; + } + + public string GetEta() { + return this.eta; + } + + public string GetAltezza() { + return this.altezza; + } + + public string GetProfessione() { + return this.professione; + } + + + public string[] GetInteressi() { + return this.interessi; + } + + public bool GetIsAvailable() { + return this.isAvailable; + } + + public void SetNome(string p_nome) { + this.nome = p_nome; + } + + public void SetCognome(string p_cognome) { + this.cognome = p_cognome; + } + public void SetSesso(string p_sesso) { + this.sesso = p_sesso; + } + + public void SetEta(string p_eta) { + this.eta = p_eta; + } + + + public void SetAltezza(string p_altezza) { + this.altezza = p_altezza; + } + + public void SetProfessione(string p_professione) { + this.professione = p_professione; + } + + public void SetInteressi(string[] p_interessi) { + this.interessi = p_interessi; + } + + public void SetIsAvailable(bool p_isAvailable) { + this.isAvailable = p_isAvailable; + } + + public void StampaCliente() { + string output; + Console.WriteLine($"Nome: {this.GetNome()}"); + Console.WriteLine($"Cognome: {this.GetCognome()}"); + Console.WriteLine($"Sesso: {this.GetSesso()}"); + Console.WriteLine($"Età: {this.GetEta()}"); + Console.WriteLine($"Altezza: {this.GetAltezza()}"); + Console.WriteLine($"Professione: {this.GetProfessione()}"); + Console.WriteLine("Interessi: "); + for (int i = 0; i < this.interessi.Length; i++) { + Console.WriteLine(interessi[i]); } - public string GetNome() - { - return this.nome; - } + output = this.isAvailable ? "Sì" : "No"; - public string GetCognome() - { - return this.cognome; - } - public string GetSesso() - { - return this.sesso; - } - - public string GetEta() - { - return this.eta; - } - - public string GetAltezza() - { - return this.altezza; - } - - public string GetProfessione() - { - return this.professione; - } - - - public string[] GetInteressi() - { - return this.interessi; - } - - public bool GetIsAvailable() - { - return this.isAvailable; - } - - public void SetNome(string p_nome) - { - this.nome = p_nome; - } - - public void SetCognome(string p_cognome) - { - this.cognome = p_cognome; - } - public void SetSesso(string p_sesso) - { - this.sesso = p_sesso; - } - - public void SetEta(string p_eta) - { - this.eta = p_eta; - } - - - public void SetAltezza(string p_altezza) - { - this.altezza = p_altezza; - } - - public void SetProfessione(string p_professione) - { - this.professione = p_professione; - } - - public void SetInteressi(string[] p_interessi) - { - this.interessi = p_interessi; - } - - public void SetIsAvailable(bool p_isAvailable) - { - this.isAvailable = p_isAvailable; - } - - public void StampaCliente() - { - string output; - Console.WriteLine($"Nome: {this.GetNome()}"); - Console.WriteLine($"Cognome: {this.GetCognome()}"); - Console.WriteLine($"Sesso: {this.GetSesso()}"); - Console.WriteLine($"Età: {this.GetEta()}"); - Console.WriteLine($"Altezza: {this.GetAltezza()}"); - Console.WriteLine($"Professione: {this.GetProfessione()}"); - Console.WriteLine("Interessi: "); - for (int i = 0; i < this.interessi.Length; i++) - { - Console.WriteLine(interessi[i]); - } - - output = this.isAvailable ? "Sì" : "No"; - - Console.WriteLine($"Disponibile: {output}"); - } + Console.WriteLine($"Disponibile: {output}"); + } } \ No newline at end of file diff --git a/Program.cs b/Program.cs index 4707858..c2c57c3 100644 --- a/Program.cs +++ b/Program.cs @@ -1,393 +1,328 @@ namespace Verifica_incontri; -class Program - { - static void Main(string[] args) - { - const int MAX_CLIENTI = 3; //da mettere a 10 prima di consegnare - int scelta = -1; - bool eccezione; - Cliente[] clienti = new Cliente[MAX_CLIENTI]; - do - { - Console.WriteLine("Inserire un'opzione:"); - Console.WriteLine("1. Inserisci dati cliente"); - Console.WriteLine("2. Visualizza clienti"); - Console.WriteLine("3. Cerca partner"); - Console.WriteLine("4. Pulisci schermo"); - Console.WriteLine("0. Esci"); - Console.Write("Scelta: "); - eccezione = false; - try - { - scelta = Convert.ToInt32(Console.ReadLine()); +class Program { + static void Main(string[] args) { + const int MAX_CLIENTI = 3; //da mettere a 10 prima di consegnare + int scelta = -1; + bool eccezione; + Cliente[] clienti = new Cliente[MAX_CLIENTI]; + do { + Console.WriteLine("Inserire un'opzione:"); + Console.WriteLine("1. Inserisci dati cliente"); + Console.WriteLine("2. Visualizza clienti"); + Console.WriteLine("3. Cerca partner"); + Console.WriteLine("4. Pulisci schermo"); + Console.WriteLine("0. Esci"); + Console.Write("Scelta: "); + eccezione = false; + try { + scelta = Convert.ToInt32(Console.ReadLine()); + } + catch (FormatException) { + eccezione = true; + Console.WriteLine("Opzione non valida."); + Pausa(); + } + if (!eccezione) { + switch (scelta) { + case 0: + break; + case 1: + InserisciClienti(clienti); + Pausa(); + break; + case 2: + if (!IsClientiPopulated(clienti)) { + Console.WriteLine("Errore: è necessario inserire i clienti prima di mostrarli."); + } + else { + StampaClienti(clienti); + } + Pausa(); + break; + case 3: + if (!IsClientiPopulated(clienti)) { + Console.WriteLine("Errore: è necessario inserire i clienti prima di mostrarli."); + } + else { + CercaPartner(clienti); + } + Pausa(); + break; + case 4: + Console.Clear(); + break; + default: + Console.WriteLine("Opzione non valida"); + Pausa(); + break; } - catch (FormatException) - { - eccezione = true; - Console.WriteLine("Opzione non valida."); + } + + } + while (scelta != 0); + } + + + static void Pausa() { + Console.WriteLine("Premere un tasto per continuare. . ."); + Console.ReadKey(); + } + + static void InserisciClienti(Cliente[] p_clienti) { + string nome, cognome, sesso, professione; + int eta = -1, altezza = -1, numeroInteressi = -1; + string[] interessi; + bool eccezione; + + for (int i = 0; i < p_clienti.Length; i++) { + Console.WriteLine($"Inserimento dati cliente n. {i + 1}:\n"); + + do { + Console.Write("Nome: "); + nome = Console.ReadLine(); + if (string.IsNullOrEmpty(nome)) { + Console.WriteLine("Errore: inserire un nome."); Pausa(); } - if (!eccezione) - { - switch (scelta) - { - case 0: - break; - case 1: - InserisciClienti(clienti); - Pausa(); - break; - case 2: - if (!IsClientiPopulated(clienti)) - { - Console.WriteLine("Errore: è necessario inserire i clienti prima di mostrarli."); - } - else - { - StampaClienti(clienti); - } - Pausa(); - break; - case 3: - if (!IsClientiPopulated(clienti)) - { - Console.WriteLine("Errore: è necessario inserire i clienti prima di mostrarli."); - } - else - { - CercaPartner(clienti); - } - Pausa(); - break; - case 4: - Console.Clear(); - break; - default: - Console.WriteLine("Opzione non valida"); - Pausa(); - break; - } - } - } - while (scelta != 0); - } + while (string.IsNullOrEmpty(nome)); - - static void Pausa() - { - Console.WriteLine("Premere un tasto per continuare. . ."); - Console.ReadKey(); - } - - static void InserisciClienti(Cliente[] p_clienti) - { - string nome, cognome, sesso, professione; - int eta = -1, altezza = -1, numeroInteressi = -1; - string[] interessi; - bool eccezione; - - for(int i = 0; i < p_clienti.Length; i++) { - Console.WriteLine($"Inserimento dati cliente n. {i + 1}:\n"); - - do - { - Console.Write("Nome: "); - nome = Console.ReadLine(); - if (string.IsNullOrEmpty(nome)) - { - Console.WriteLine("Errore: inserire un nome."); - Pausa(); - } + do { + Console.Write("Cognome: "); + cognome = Console.ReadLine(); + if (string.IsNullOrEmpty(cognome)) { + Console.WriteLine("Errore: inserire un cognome."); + Pausa(); } - while (string.IsNullOrEmpty(nome)); - - do - { - Console.Write("Cognome: "); - cognome = Console.ReadLine(); - if (string.IsNullOrEmpty(cognome)) - { - Console.WriteLine("Errore: inserire un cognome."); - Pausa(); - } - } - while (string.IsNullOrEmpty(cognome)); - - do - { - Console.Write("Sesso: "); - sesso = Console.ReadLine(); - if (string.IsNullOrEmpty(sesso)) - { - Console.WriteLine("Errore: inserire un sesso."); - Pausa(); - } - } - while (string.IsNullOrEmpty(sesso)); - - do - { - Console.Write("Età: "); - eccezione = false; - try - { - eta = Convert.ToInt32(Console.ReadLine()); - } - catch (FormatException) - { - eccezione = true; - Console.WriteLine("Errore: età non valida"); - Pausa(); - } - if (!eccezione) - { - if(eta <= 0) - { - Console.WriteLine("Errore: età non valida"); - Pausa(); - } - } - } - while (eccezione || eta <= 0); - - do - { - Console.Write("Altezza (cm): "); - eccezione = false; - try - { - altezza = Convert.ToInt32(Console.ReadLine()); - } - catch (FormatException) - { - eccezione = true; - Console.WriteLine("Errore: altezza non valida"); - Pausa(); - } - if (!eccezione) - { - if (altezza <= 0) - { - Console.WriteLine("Errore: altezza non valida"); - Pausa(); - } - } - } - while (eccezione || altezza <= 0); - - do - { - Console.Write("Professione: "); - professione = Console.ReadLine(); - if (string.IsNullOrEmpty(professione)) - { - Console.WriteLine("Errore: inserire una professione."); - Pausa(); - } - } - while (string.IsNullOrEmpty(professione)); - - do - { - Console.Write("Numero di interessi: "); - eccezione = false; - try - { - numeroInteressi = Convert.ToInt32(Console.ReadLine()); - } - catch (FormatException) - { - eccezione = true; - Console.WriteLine("Errore: numero di interessi non valido"); - Pausa(); - } - if (!eccezione) - { - if (numeroInteressi <= 0) - { - Console.WriteLine("Errore: numero di interessi non valido"); - Pausa(); - } - } - } - while (eccezione || numeroInteressi <= 0); - - interessi = new string[numeroInteressi]; - - for (int j = 0; j < numeroInteressi; j++) - { - do - { - Console.Write($"Interesse n. {j + 1}: "); - interessi[j] = Console.ReadLine(); - if (string.IsNullOrEmpty(interessi[j])) - { - Console.WriteLine("Errore: inserire un'interesse."); - Pausa(); - } - } - while (string.IsNullOrEmpty(interessi[j])); - } - - p_clienti[i] = new Cliente(nome, cognome, sesso, Convert.ToString(eta), Convert.ToString(altezza), professione, interessi); - - Console.WriteLine($"\n\nCliente {i+1} creato con successo."); } + while (string.IsNullOrEmpty(cognome)); - - - - } - - static bool IsClientiPopulated(Cliente[] p_clienti) - { - bool ritorno; - if (p_clienti[0] == null) - { - ritorno = false; - } - else - { - ritorno = true; - } - return ritorno; - } - - static void StampaClienti(Cliente[] p_clienti) - { - for (int i = 0; i < p_clienti.Length; i++) - { - Console.WriteLine($"Cliente n. {i + 1}:"); - p_clienti[i].StampaCliente(); - Console.WriteLine(); - } - } - - static void CercaPartner(Cliente[] p_clienti) - { - string sesso; - int etaMin = -1, etaMax = -1, j = 0, scelta = 0; - bool eccezione; - int[] matches = new int[p_clienti.Length]; - for (int i = 0;i < p_clienti.Length; i++) - { - matches[i] = -1; - } - - do - { - Console.Write("Inserire il sesso da cercare: "); - sesso = Console.ReadLine().ToLower().Trim(); - if (string.IsNullOrEmpty(sesso)) - { + do { + Console.Write("Sesso: "); + sesso = Console.ReadLine(); + if (string.IsNullOrEmpty(sesso)) { Console.WriteLine("Errore: inserire un sesso."); Pausa(); } } while (string.IsNullOrEmpty(sesso)); - do - { - Console.Write("Inserire l'età minima: "); + do { + Console.Write("Età: "); eccezione = false; - try - { - etaMin = Convert.ToInt32(Console.ReadLine()); + try { + eta = Convert.ToInt32(Console.ReadLine()); } - catch (FormatException) - { + catch (FormatException) { eccezione = true; Console.WriteLine("Errore: età non valida"); Pausa(); } - if (!eccezione) - { - if (etaMin <= 0) - { + if (!eccezione) { + if (eta <= 0) { Console.WriteLine("Errore: età non valida"); Pausa(); } } } - while (eccezione || etaMin <= 0); + while (eccezione || eta <= 0); - do - { - Console.Write("Inserire l'età massima: "); + do { + Console.Write("Altezza (cm): "); eccezione = false; - try - { - etaMax = Convert.ToInt32(Console.ReadLine()); + try { + altezza = Convert.ToInt32(Console.ReadLine()); } - catch (FormatException) - { + catch (FormatException) { eccezione = true; - Console.WriteLine("Errore: età non valida"); + Console.WriteLine("Errore: altezza non valida"); Pausa(); } - if (!eccezione) - { - if (etaMax <= 0) - { - Console.WriteLine("Errore: età non valida"); + if (!eccezione) { + if (altezza <= 0) { + Console.WriteLine("Errore: altezza non valida"); Pausa(); } } } - while (eccezione || etaMax <= 0); + while (eccezione || altezza <= 0); - for (int i = 0; i < p_clienti.Length; i++) { - if(Convert.ToInt32(p_clienti[i].GetEta()) >= etaMin && - Convert.ToInt32(p_clienti[i].GetEta()) <= etaMax && - p_clienti[i].GetSesso().ToLower().Trim() == sesso) - { - Console.WriteLine("Trovata una corrispondenza:\n"); - Console.WriteLine($"Nome: {p_clienti[i].GetNome()}"); - Console.WriteLine($"Cognome: {p_clienti[i].GetCognome()}"); - Console.WriteLine($"Età: {p_clienti[i].GetEta()}"); - Console.WriteLine(); - matches[j] = i; - j++; + do { + Console.Write("Professione: "); + professione = Console.ReadLine(); + if (string.IsNullOrEmpty(professione)) { + Console.WriteLine("Errore: inserire una professione."); + Pausa(); } } - do - { - Console.WriteLine("Selezionare la corrispondenza:"); - for (int i = 0; i < matches.Length && matches[i] != -1; i++) - { - Console.WriteLine($"Corrispondenza n. {i + 1}:\n"); - Console.WriteLine($"Nome: {p_clienti[matches[i]].GetNome()}"); - Console.WriteLine($"Cognome: {p_clienti[matches[i]].GetCognome()}"); - Console.WriteLine($"Età: {p_clienti[matches[i]].GetEta()}"); + while (string.IsNullOrEmpty(professione)); + + do { + Console.Write("Numero di interessi: "); + eccezione = false; + try { + numeroInteressi = Convert.ToInt32(Console.ReadLine()); } + catch (FormatException) { + eccezione = true; + Console.WriteLine("Errore: numero di interessi non valido"); + Pausa(); + } + if (!eccezione) { + if (numeroInteressi <= 0) { + Console.WriteLine("Errore: numero di interessi non valido"); + Pausa(); + } + } + } + while (eccezione || numeroInteressi <= 0); + + interessi = new string[numeroInteressi]; + + for (int j = 0; j < numeroInteressi; j++) { + do { + Console.Write($"Interesse n. {j + 1}: "); + interessi[j] = Console.ReadLine(); + if (string.IsNullOrEmpty(interessi[j])) { + Console.WriteLine("Errore: inserire un'interesse."); + Pausa(); + } + } + while (string.IsNullOrEmpty(interessi[j])); + } + + p_clienti[i] = new Cliente(nome, cognome, sesso, Convert.ToString(eta), Convert.ToString(altezza), professione, interessi); + + Console.WriteLine($"\n\nCliente {i + 1} creato con successo."); + } + + + + + } + + static bool IsClientiPopulated(Cliente[] p_clienti) { + bool ritorno; + if (p_clienti[0] == null) { + ritorno = false; + } + else { + ritorno = true; + } + return ritorno; + } + + static void StampaClienti(Cliente[] p_clienti) { + for (int i = 0; i < p_clienti.Length; i++) { + Console.WriteLine($"Cliente n. {i + 1}:"); + p_clienti[i].StampaCliente(); + Console.WriteLine(); + } + } + + static void CercaPartner(Cliente[] p_clienti) { + string sesso; + int etaMin = -1, etaMax = -1, j = 0, scelta = 0; + bool eccezione; + int[] matches = new int[p_clienti.Length]; + for (int i = 0; i < p_clienti.Length; i++) { + matches[i] = -1; + } + + do { + Console.Write("Inserire il sesso da cercare: "); + sesso = Console.ReadLine().ToLower().Trim(); + if (string.IsNullOrEmpty(sesso)) { + Console.WriteLine("Errore: inserire un sesso."); + Pausa(); + } + } + while (string.IsNullOrEmpty(sesso)); + + do { + Console.Write("Inserire l'età minima: "); + eccezione = false; + try { + etaMin = Convert.ToInt32(Console.ReadLine()); + } + catch (FormatException) { + eccezione = true; + Console.WriteLine("Errore: età non valida"); + Pausa(); + } + if (!eccezione) { + if (etaMin <= 0) { + Console.WriteLine("Errore: età non valida"); + Pausa(); + } + } + } + while (eccezione || etaMin <= 0); + + do { + Console.Write("Inserire l'età massima: "); + eccezione = false; + try { + etaMax = Convert.ToInt32(Console.ReadLine()); + } + catch (FormatException) { + eccezione = true; + Console.WriteLine("Errore: età non valida"); + Pausa(); + } + if (!eccezione) { + if (etaMax <= 0) { + Console.WriteLine("Errore: età non valida"); + Pausa(); + } + } + } + while (eccezione || etaMax <= 0); + + for (int i = 0; i < p_clienti.Length; i++) { + if (Convert.ToInt32(p_clienti[i].GetEta()) >= etaMin && + Convert.ToInt32(p_clienti[i].GetEta()) <= etaMax && + p_clienti[i].GetSesso().ToLower().Trim() == sesso) { + Console.WriteLine("Trovata una corrispondenza:\n"); + Console.WriteLine($"Nome: {p_clienti[i].GetNome()}"); + Console.WriteLine($"Cognome: {p_clienti[i].GetCognome()}"); + Console.WriteLine($"Età: {p_clienti[i].GetEta()}"); Console.WriteLine(); - Console.Write("Scelta: "); + matches[j] = i; + j++; + } + } + do { + Console.WriteLine("Selezionare la corrispondenza:"); + for (int i = 0; i < matches.Length && matches[i] != -1; i++) { + Console.WriteLine($"Corrispondenza n. {i + 1}:\n"); + Console.WriteLine($"Nome: {p_clienti[matches[i]].GetNome()}"); + Console.WriteLine($"Cognome: {p_clienti[matches[i]].GetCognome()}"); + Console.WriteLine($"Età: {p_clienti[matches[i]].GetEta()}"); + } + Console.WriteLine(); + Console.Write("Scelta: "); - eccezione = false; - try - { - scelta = Convert.ToInt32(Console.ReadLine()); - } - catch (FormatException) - { - eccezione = true; + eccezione = false; + try { + scelta = Convert.ToInt32(Console.ReadLine()); + } + catch (FormatException) { + eccezione = true; + Console.WriteLine("Opzione non valida."); + Pausa(); + } + if (!eccezione) { + if (scelta < 1 || scelta >= p_clienti.Length) { Console.WriteLine("Opzione non valida."); Pausa(); } - if (!eccezione) - { - if (scelta < 1 || scelta >= p_clienti.Length) - { - Console.WriteLine("Opzione non valida."); - Pausa(); - } - } - } - while (eccezione && !(scelta < 1 || scelta >= p_clienti.Length)); //controllo non funzionante - p_clienti[scelta - 1].SetIsAvailable(false); - Console.WriteLine("Match eseguito"); + } - } \ No newline at end of file + while (eccezione && !(scelta < 1 || scelta >= p_clienti.Length)); //controllo non funzionante + p_clienti[scelta - 1].SetIsAvailable(false); + Console.WriteLine("Match eseguito"); + } +} \ No newline at end of file