Formattazione
This commit is contained in:
59
Cliente.cs
59
Cliente.cs
@@ -1,7 +1,7 @@
|
||||
namespace Verifica_incontri;
|
||||
|
||||
class Cliente {
|
||||
string nome;
|
||||
string nome;
|
||||
string cognome;
|
||||
string sesso;
|
||||
string eta;
|
||||
@@ -10,8 +10,7 @@ string nome;
|
||||
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)
|
||||
{
|
||||
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;
|
||||
@@ -21,88 +20,71 @@ string nome;
|
||||
this.interessi = p_interessi;
|
||||
}
|
||||
|
||||
public string GetNome()
|
||||
{
|
||||
public string GetNome() {
|
||||
return this.nome;
|
||||
}
|
||||
|
||||
public string GetCognome()
|
||||
{
|
||||
public string GetCognome() {
|
||||
return this.cognome;
|
||||
}
|
||||
public string GetSesso()
|
||||
{
|
||||
public string GetSesso() {
|
||||
return this.sesso;
|
||||
}
|
||||
|
||||
public string GetEta()
|
||||
{
|
||||
public string GetEta() {
|
||||
return this.eta;
|
||||
}
|
||||
|
||||
public string GetAltezza()
|
||||
{
|
||||
public string GetAltezza() {
|
||||
return this.altezza;
|
||||
}
|
||||
|
||||
public string GetProfessione()
|
||||
{
|
||||
public string GetProfessione() {
|
||||
return this.professione;
|
||||
}
|
||||
|
||||
|
||||
public string[] GetInteressi()
|
||||
{
|
||||
public string[] GetInteressi() {
|
||||
return this.interessi;
|
||||
}
|
||||
|
||||
public bool GetIsAvailable()
|
||||
{
|
||||
public bool GetIsAvailable() {
|
||||
return this.isAvailable;
|
||||
}
|
||||
|
||||
public void SetNome(string p_nome)
|
||||
{
|
||||
public void SetNome(string p_nome) {
|
||||
this.nome = p_nome;
|
||||
}
|
||||
|
||||
public void SetCognome(string p_cognome)
|
||||
{
|
||||
public void SetCognome(string p_cognome) {
|
||||
this.cognome = p_cognome;
|
||||
}
|
||||
public void SetSesso(string p_sesso)
|
||||
{
|
||||
public void SetSesso(string p_sesso) {
|
||||
this.sesso = p_sesso;
|
||||
}
|
||||
|
||||
public void SetEta(string p_eta)
|
||||
{
|
||||
public void SetEta(string p_eta) {
|
||||
this.eta = p_eta;
|
||||
}
|
||||
|
||||
|
||||
public void SetAltezza(string p_altezza)
|
||||
{
|
||||
public void SetAltezza(string p_altezza) {
|
||||
this.altezza = p_altezza;
|
||||
}
|
||||
|
||||
public void SetProfessione(string p_professione)
|
||||
{
|
||||
public void SetProfessione(string p_professione) {
|
||||
this.professione = p_professione;
|
||||
}
|
||||
|
||||
public void SetInteressi(string[] p_interessi)
|
||||
{
|
||||
public void SetInteressi(string[] p_interessi) {
|
||||
this.interessi = p_interessi;
|
||||
}
|
||||
|
||||
public void SetIsAvailable(bool p_isAvailable)
|
||||
{
|
||||
public void SetIsAvailable(bool p_isAvailable) {
|
||||
this.isAvailable = p_isAvailable;
|
||||
}
|
||||
|
||||
public void StampaCliente()
|
||||
{
|
||||
public void StampaCliente() {
|
||||
string output;
|
||||
Console.WriteLine($"Nome: {this.GetNome()}");
|
||||
Console.WriteLine($"Cognome: {this.GetCognome()}");
|
||||
@@ -111,8 +93,7 @@ string nome;
|
||||
Console.WriteLine($"Altezza: {this.GetAltezza()}");
|
||||
Console.WriteLine($"Professione: {this.GetProfessione()}");
|
||||
Console.WriteLine("Interessi: ");
|
||||
for (int i = 0; i < this.interessi.Length; i++)
|
||||
{
|
||||
for (int i = 0; i < this.interessi.Length; i++) {
|
||||
Console.WriteLine(interessi[i]);
|
||||
}
|
||||
|
||||
|
||||
203
Program.cs
203
Program.cs
@@ -1,15 +1,12 @@
|
||||
namespace Verifica_incontri;
|
||||
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
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
|
||||
{
|
||||
do {
|
||||
Console.WriteLine("Inserire un'opzione:");
|
||||
Console.WriteLine("1. Inserisci dati cliente");
|
||||
Console.WriteLine("2. Visualizza clienti");
|
||||
@@ -18,20 +15,16 @@ class Program
|
||||
Console.WriteLine("0. Esci");
|
||||
Console.Write("Scelta: ");
|
||||
eccezione = false;
|
||||
try
|
||||
{
|
||||
try {
|
||||
scelta = Convert.ToInt32(Console.ReadLine());
|
||||
}
|
||||
catch (FormatException)
|
||||
{
|
||||
catch (FormatException) {
|
||||
eccezione = true;
|
||||
Console.WriteLine("Opzione non valida.");
|
||||
Pausa();
|
||||
}
|
||||
if (!eccezione)
|
||||
{
|
||||
switch (scelta)
|
||||
{
|
||||
if (!eccezione) {
|
||||
switch (scelta) {
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
@@ -39,23 +32,19 @@ class Program
|
||||
Pausa();
|
||||
break;
|
||||
case 2:
|
||||
if (!IsClientiPopulated(clienti))
|
||||
{
|
||||
if (!IsClientiPopulated(clienti)) {
|
||||
Console.WriteLine("Errore: è necessario inserire i clienti prima di mostrarli.");
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
StampaClienti(clienti);
|
||||
}
|
||||
Pausa();
|
||||
break;
|
||||
case 3:
|
||||
if (!IsClientiPopulated(clienti))
|
||||
{
|
||||
if (!IsClientiPopulated(clienti)) {
|
||||
Console.WriteLine("Errore: è necessario inserire i clienti prima di mostrarli.");
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
CercaPartner(clienti);
|
||||
}
|
||||
Pausa();
|
||||
@@ -75,76 +64,63 @@ class Program
|
||||
}
|
||||
|
||||
|
||||
static void Pausa()
|
||||
{
|
||||
static void Pausa() {
|
||||
Console.WriteLine("Premere un tasto per continuare. . .");
|
||||
Console.ReadKey();
|
||||
}
|
||||
|
||||
static void InserisciClienti(Cliente[] p_clienti)
|
||||
{
|
||||
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++) {
|
||||
for (int i = 0; i < p_clienti.Length; i++) {
|
||||
Console.WriteLine($"Inserimento dati cliente n. {i + 1}:\n");
|
||||
|
||||
do
|
||||
{
|
||||
do {
|
||||
Console.Write("Nome: ");
|
||||
nome = Console.ReadLine();
|
||||
if (string.IsNullOrEmpty(nome))
|
||||
{
|
||||
if (string.IsNullOrEmpty(nome)) {
|
||||
Console.WriteLine("Errore: inserire un nome.");
|
||||
Pausa();
|
||||
}
|
||||
}
|
||||
while (string.IsNullOrEmpty(nome));
|
||||
|
||||
do
|
||||
{
|
||||
do {
|
||||
Console.Write("Cognome: ");
|
||||
cognome = Console.ReadLine();
|
||||
if (string.IsNullOrEmpty(cognome))
|
||||
{
|
||||
if (string.IsNullOrEmpty(cognome)) {
|
||||
Console.WriteLine("Errore: inserire un cognome.");
|
||||
Pausa();
|
||||
}
|
||||
}
|
||||
while (string.IsNullOrEmpty(cognome));
|
||||
|
||||
do
|
||||
{
|
||||
do {
|
||||
Console.Write("Sesso: ");
|
||||
sesso = Console.ReadLine();
|
||||
if (string.IsNullOrEmpty(sesso))
|
||||
{
|
||||
if (string.IsNullOrEmpty(sesso)) {
|
||||
Console.WriteLine("Errore: inserire un sesso.");
|
||||
Pausa();
|
||||
}
|
||||
}
|
||||
while (string.IsNullOrEmpty(sesso));
|
||||
|
||||
do
|
||||
{
|
||||
do {
|
||||
Console.Write("Età: ");
|
||||
eccezione = false;
|
||||
try
|
||||
{
|
||||
try {
|
||||
eta = Convert.ToInt32(Console.ReadLine());
|
||||
}
|
||||
catch (FormatException)
|
||||
{
|
||||
catch (FormatException) {
|
||||
eccezione = true;
|
||||
Console.WriteLine("Errore: età non valida");
|
||||
Pausa();
|
||||
}
|
||||
if (!eccezione)
|
||||
{
|
||||
if(eta <= 0)
|
||||
{
|
||||
if (!eccezione) {
|
||||
if (eta <= 0) {
|
||||
Console.WriteLine("Errore: età non valida");
|
||||
Pausa();
|
||||
}
|
||||
@@ -152,24 +128,19 @@ class Program
|
||||
}
|
||||
while (eccezione || eta <= 0);
|
||||
|
||||
do
|
||||
{
|
||||
do {
|
||||
Console.Write("Altezza (cm): ");
|
||||
eccezione = false;
|
||||
try
|
||||
{
|
||||
try {
|
||||
altezza = Convert.ToInt32(Console.ReadLine());
|
||||
}
|
||||
catch (FormatException)
|
||||
{
|
||||
catch (FormatException) {
|
||||
eccezione = true;
|
||||
Console.WriteLine("Errore: altezza non valida");
|
||||
Pausa();
|
||||
}
|
||||
if (!eccezione)
|
||||
{
|
||||
if (altezza <= 0)
|
||||
{
|
||||
if (!eccezione) {
|
||||
if (altezza <= 0) {
|
||||
Console.WriteLine("Errore: altezza non valida");
|
||||
Pausa();
|
||||
}
|
||||
@@ -177,36 +148,29 @@ class Program
|
||||
}
|
||||
while (eccezione || altezza <= 0);
|
||||
|
||||
do
|
||||
{
|
||||
do {
|
||||
Console.Write("Professione: ");
|
||||
professione = Console.ReadLine();
|
||||
if (string.IsNullOrEmpty(professione))
|
||||
{
|
||||
if (string.IsNullOrEmpty(professione)) {
|
||||
Console.WriteLine("Errore: inserire una professione.");
|
||||
Pausa();
|
||||
}
|
||||
}
|
||||
while (string.IsNullOrEmpty(professione));
|
||||
|
||||
do
|
||||
{
|
||||
do {
|
||||
Console.Write("Numero di interessi: ");
|
||||
eccezione = false;
|
||||
try
|
||||
{
|
||||
try {
|
||||
numeroInteressi = Convert.ToInt32(Console.ReadLine());
|
||||
}
|
||||
catch (FormatException)
|
||||
{
|
||||
catch (FormatException) {
|
||||
eccezione = true;
|
||||
Console.WriteLine("Errore: numero di interessi non valido");
|
||||
Pausa();
|
||||
}
|
||||
if (!eccezione)
|
||||
{
|
||||
if (numeroInteressi <= 0)
|
||||
{
|
||||
if (!eccezione) {
|
||||
if (numeroInteressi <= 0) {
|
||||
Console.WriteLine("Errore: numero di interessi non valido");
|
||||
Pausa();
|
||||
}
|
||||
@@ -216,14 +180,11 @@ class Program
|
||||
|
||||
interessi = new string[numeroInteressi];
|
||||
|
||||
for (int j = 0; j < numeroInteressi; j++)
|
||||
{
|
||||
do
|
||||
{
|
||||
for (int j = 0; j < numeroInteressi; j++) {
|
||||
do {
|
||||
Console.Write($"Interesse n. {j + 1}: ");
|
||||
interessi[j] = Console.ReadLine();
|
||||
if (string.IsNullOrEmpty(interessi[j]))
|
||||
{
|
||||
if (string.IsNullOrEmpty(interessi[j])) {
|
||||
Console.WriteLine("Errore: inserire un'interesse.");
|
||||
Pausa();
|
||||
}
|
||||
@@ -233,7 +194,7 @@ class Program
|
||||
|
||||
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.");
|
||||
Console.WriteLine($"\n\nCliente {i + 1} creato con successo.");
|
||||
}
|
||||
|
||||
|
||||
@@ -241,71 +202,57 @@ class Program
|
||||
|
||||
}
|
||||
|
||||
static bool IsClientiPopulated(Cliente[] p_clienti)
|
||||
{
|
||||
static bool IsClientiPopulated(Cliente[] p_clienti) {
|
||||
bool ritorno;
|
||||
if (p_clienti[0] == null)
|
||||
{
|
||||
if (p_clienti[0] == null) {
|
||||
ritorno = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
ritorno = true;
|
||||
}
|
||||
return ritorno;
|
||||
}
|
||||
|
||||
static void StampaClienti(Cliente[] p_clienti)
|
||||
{
|
||||
for (int i = 0; i < p_clienti.Length; i++)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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++)
|
||||
{
|
||||
for (int i = 0; i < p_clienti.Length; i++) {
|
||||
matches[i] = -1;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
do {
|
||||
Console.Write("Inserire il sesso da cercare: ");
|
||||
sesso = Console.ReadLine().ToLower().Trim();
|
||||
if (string.IsNullOrEmpty(sesso))
|
||||
{
|
||||
if (string.IsNullOrEmpty(sesso)) {
|
||||
Console.WriteLine("Errore: inserire un sesso.");
|
||||
Pausa();
|
||||
}
|
||||
}
|
||||
while (string.IsNullOrEmpty(sesso));
|
||||
|
||||
do
|
||||
{
|
||||
do {
|
||||
Console.Write("Inserire l'età minima: ");
|
||||
eccezione = false;
|
||||
try
|
||||
{
|
||||
try {
|
||||
etaMin = 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 (etaMin <= 0) {
|
||||
Console.WriteLine("Errore: età non valida");
|
||||
Pausa();
|
||||
}
|
||||
@@ -313,24 +260,19 @@ class Program
|
||||
}
|
||||
while (eccezione || etaMin <= 0);
|
||||
|
||||
do
|
||||
{
|
||||
do {
|
||||
Console.Write("Inserire l'età massima: ");
|
||||
eccezione = false;
|
||||
try
|
||||
{
|
||||
try {
|
||||
etaMax = Convert.ToInt32(Console.ReadLine());
|
||||
}
|
||||
catch (FormatException)
|
||||
{
|
||||
catch (FormatException) {
|
||||
eccezione = true;
|
||||
Console.WriteLine("Errore: età non valida");
|
||||
Pausa();
|
||||
}
|
||||
if (!eccezione)
|
||||
{
|
||||
if (etaMax <= 0)
|
||||
{
|
||||
if (!eccezione) {
|
||||
if (etaMax <= 0) {
|
||||
Console.WriteLine("Errore: età non valida");
|
||||
Pausa();
|
||||
}
|
||||
@@ -339,10 +281,9 @@ class Program
|
||||
while (eccezione || etaMax <= 0);
|
||||
|
||||
for (int i = 0; i < p_clienti.Length; i++) {
|
||||
if(Convert.ToInt32(p_clienti[i].GetEta()) >= etaMin &&
|
||||
if (Convert.ToInt32(p_clienti[i].GetEta()) >= etaMin &&
|
||||
Convert.ToInt32(p_clienti[i].GetEta()) <= etaMax &&
|
||||
p_clienti[i].GetSesso().ToLower().Trim() == sesso)
|
||||
{
|
||||
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()}");
|
||||
@@ -352,11 +293,9 @@ class Program
|
||||
j++;
|
||||
}
|
||||
}
|
||||
do
|
||||
{
|
||||
do {
|
||||
Console.WriteLine("Selezionare la corrispondenza:");
|
||||
for (int i = 0; i < matches.Length && matches[i] != -1; i++)
|
||||
{
|
||||
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()}");
|
||||
@@ -366,20 +305,16 @@ class Program
|
||||
Console.Write("Scelta: ");
|
||||
|
||||
eccezione = false;
|
||||
try
|
||||
{
|
||||
try {
|
||||
scelta = Convert.ToInt32(Console.ReadLine());
|
||||
}
|
||||
catch (FormatException)
|
||||
{
|
||||
catch (FormatException) {
|
||||
eccezione = true;
|
||||
Console.WriteLine("Opzione non valida.");
|
||||
Pausa();
|
||||
}
|
||||
if (!eccezione)
|
||||
{
|
||||
if (scelta < 1 || scelta >= p_clienti.Length)
|
||||
{
|
||||
if (!eccezione) {
|
||||
if (scelta < 1 || scelta >= p_clienti.Length) {
|
||||
Console.WriteLine("Opzione non valida.");
|
||||
Pausa();
|
||||
}
|
||||
@@ -390,4 +325,4 @@ class Program
|
||||
p_clienti[scelta - 1].SetIsAvailable(false);
|
||||
Console.WriteLine("Match eseguito");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user