Opzione 4

This commit is contained in:
La Programmatrice Verde 2025-04-16 09:41:41 +02:00
parent c92496d0b5
commit ae01f25a36
10 changed files with 81 additions and 23 deletions

View File

@ -6,8 +6,21 @@ class Dispenser {
double quantitàErogata; double quantitàErogata;
double quantitàContenuta; double quantitàContenuta;
public Dispenser(string p_tipologia, double p_quantitàErogata, double p_quantitàContenuta, double p_capienza) { //valori dispenser
this.tipologia = p_tipologia; const string TIPOLOGIA1 = "Standard";
const string TIPOLOGIA2 = "Custom";
//valori standard
const double CAPIENZA = 500;
const double EROGAZIONE = 10;
public Dispenser() {
this.tipologia = TIPOLOGIA1;
this.capienza = CAPIENZA;
this.quantitàContenuta = CAPIENZA;
this.quantitàErogata = EROGAZIONE;
}
public Dispenser(double p_quantitàErogata, double p_quantitàContenuta, double p_capienza) {
this.tipologia = TIPOLOGIA2;
this.quantitàErogata = p_quantitàErogata; this.quantitàErogata = p_quantitàErogata;
this.quantitàContenuta = p_quantitàContenuta; this.quantitàContenuta = p_quantitàContenuta;
this.capienza = p_capienza; this.capienza = p_capienza;
@ -40,11 +53,16 @@ class Dispenser {
Console.WriteLine($"Quantità contenuta: {this.GetQuantitàContenuta()}"); Console.WriteLine($"Quantità contenuta: {this.GetQuantitàContenuta()}");
} }
public void Erogazione() { public double Erogazione() {
if (this.quantitàContenuta - this.quantitàErogata <= 0) { double ritorno;
if (this.quantitàContenuta - this.quantitàErogata < 0) {
ritorno = 0;
} }
else {
this.quantitàContenuta = this.quantitàContenuta - this.quantitàErogata; this.quantitàContenuta = this.quantitàContenuta - this.quantitàErogata;
ritorno = this.quantitàContenuta;
}
return ritorno;
} }
public double Riempimento(double p_refill) { public double Riempimento(double p_refill) {

View File

@ -3,15 +3,10 @@
class Program { class Program {
static void Main(string[] args) { static void Main(string[] args) {
Console.Clear(); Console.Clear();
//valori dispenser double quantitàErogata, quantitàContenuta, capienza, quantitàRimasta;
const string TIPOLOGIA1 = "Standard";
const string TIPOLOGIA2 = "Custom";
//valori standard
const double CAPIENZA = 500;
const double EROGAZIONE = 10;
double quantitàErogata, quantitàContenuta, capienza;
int scelta, input, i = 0; int scelta, input, i = 0;
Dispenser[] dispensers = null; Dispenser[] dispensers;
bool oggettoEsistente;
Console.Write("Quanti dispenser considerare? "); Console.Write("Quanti dispenser considerare? ");
input = Convert.ToInt32(Console.ReadLine()); input = Convert.ToInt32(Console.ReadLine());
@ -37,7 +32,7 @@ class Program {
Console.WriteLine($"Errore: non si possono creare più di {dispensers.Length} dispensers."); Console.WriteLine($"Errore: non si possono creare più di {dispensers.Length} dispensers.");
} }
else { else {
dispensers[i] = new Dispenser(TIPOLOGIA1, EROGAZIONE, CAPIENZA, CAPIENZA); dispensers[i] = new Dispenser();
i++; i++;
Console.WriteLine("Dispenser standard creato."); Console.WriteLine("Dispenser standard creato.");
} }
@ -75,7 +70,7 @@ class Program {
} }
} }
while (quantitàContenuta <= 0); while (quantitàContenuta <= 0);
dispensers[i] = new Dispenser(TIPOLOGIA2, quantitàErogata, quantitàContenuta, capienza); dispensers[i] = new Dispenser(quantitàErogata, quantitàContenuta, capienza);
i++; i++;
} }
Pausa(); Pausa();
@ -83,11 +78,36 @@ class Program {
case 3: case 3:
Console.Clear(); Console.Clear();
oggettoEsistente = true;
for (int j = 0; j < dispensers.Length && oggettoEsistente; j++) {
if (dispensers[j] == null) {
oggettoEsistente = false;
}
}
if (!oggettoEsistente) {
Console.WriteLine("Errore: è necessario creare *tutti* i dispenser prima di mostrarli.");
}
else {
for (int j = 0; j < dispensers.Length; j++) { for (int j = 0; j < dispensers.Length; j++) {
Console.WriteLine($"Dispenser {j + 1}:"); Console.WriteLine($"Dispenser {j + 1}:");
dispensers[j].StampaDispenser(); dispensers[j].StampaDispenser();
Console.WriteLine(); Console.WriteLine();
} }
}
Pausa();
break;
case 4:
Console.Clear();
quantitàRimasta = SelezionaDispenser(dispensers).Erogazione();
if (quantitàRimasta == 0) {
Console.WriteLine("Il dispenser è vuoto.");
}
else {
Console.WriteLine($"Quantità rimasta: {quantitàRimasta}");
}
Console.WriteLine("Erogazione effettuata");
Console.WriteLine();
Pausa(); Pausa();
break; break;
} }
@ -100,4 +120,24 @@ class Program {
Console.ReadKey(); Console.ReadKey();
Console.Clear(); Console.Clear();
} }
static Dispenser SelezionaDispenser(Dispenser[] p_dispensers) {
int scelta;
do {
Console.WriteLine("Quale dispenser selezionare?");
for (int i = 0; i < p_dispensers.Length; i++) {
Console.WriteLine($"{i}. Dispenser {i + 1}");
}
Console.Write("Scelta: ");
scelta = Convert.ToInt32(Console.ReadLine());
if (scelta < 0 || scelta >= p_dispensers.Length) {
Console.WriteLine("Errore: il dispenser selezionato non esiste.");
Pausa();
}
}
while (scelta < 0 || scelta >= p_dispensers.Length);
return p_dispensers[scelta];
}
} }

View File

@ -13,10 +13,10 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("dispenser_sapone")] [assembly: System.Reflection.AssemblyCompanyAttribute("dispenser_sapone")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+cbf1ec3c38bb4c3492a74ebd2e4d930e5180714f")] [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+c92496d0b5143b7a429033b8cd9a249053a08a75")]
[assembly: System.Reflection.AssemblyProductAttribute("dispenser_sapone")] [assembly: System.Reflection.AssemblyProductAttribute("dispenser_sapone")]
[assembly: System.Reflection.AssemblyTitleAttribute("dispenser_sapone")] [assembly: System.Reflection.AssemblyTitleAttribute("dispenser_sapone")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// Generated by the MSBuild WriteCodeFragment class. // Generato dalla classe WriteCodeFragment di MSBuild.

View File

@ -1 +1 @@
e6431b311817db60eb5094c983152681b5926e4c01407422d780ffd52806cf09 a590da0f58f352d3ab954b67f58709ab6a266a4e1bc77c97eab6bb12202a17f9