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àContenuta;
public Dispenser(string p_tipologia, double p_quantitàErogata, double p_quantitàContenuta, double p_capienza) {
this.tipologia = p_tipologia;
//valori dispenser
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àContenuta = p_quantitàContenuta;
this.capienza = p_capienza;
@ -40,11 +53,16 @@ class Dispenser {
Console.WriteLine($"Quantità contenuta: {this.GetQuantitàContenuta()}");
}
public void Erogazione() {
if (this.quantitàContenuta - this.quantitàErogata <= 0) {
public double Erogazione() {
double ritorno;
if (this.quantitàContenuta - this.quantitàErogata < 0) {
ritorno = 0;
}
this.quantitàContenuta = this.quantitàContenuta - this.quantitàErogata;
else {
this.quantitàContenuta = this.quantitàContenuta - this.quantitàErogata;
ritorno = this.quantitàContenuta;
}
return ritorno;
}
public double Riempimento(double p_refill) {

View File

@ -3,15 +3,10 @@
class Program {
static void Main(string[] args) {
Console.Clear();
//valori dispenser
const string TIPOLOGIA1 = "Standard";
const string TIPOLOGIA2 = "Custom";
//valori standard
const double CAPIENZA = 500;
const double EROGAZIONE = 10;
double quantitàErogata, quantitàContenuta, capienza;
double quantitàErogata, quantitàContenuta, capienza, quantitàRimasta;
int scelta, input, i = 0;
Dispenser[] dispensers = null;
Dispenser[] dispensers;
bool oggettoEsistente;
Console.Write("Quanti dispenser considerare? ");
input = Convert.ToInt32(Console.ReadLine());
@ -37,7 +32,7 @@ class Program {
Console.WriteLine($"Errore: non si possono creare più di {dispensers.Length} dispensers.");
}
else {
dispensers[i] = new Dispenser(TIPOLOGIA1, EROGAZIONE, CAPIENZA, CAPIENZA);
dispensers[i] = new Dispenser();
i++;
Console.WriteLine("Dispenser standard creato.");
}
@ -75,7 +70,7 @@ class Program {
}
}
while (quantitàContenuta <= 0);
dispensers[i] = new Dispenser(TIPOLOGIA2, quantitàErogata, quantitàContenuta, capienza);
dispensers[i] = new Dispenser(quantitàErogata, quantitàContenuta, capienza);
i++;
}
Pausa();
@ -83,11 +78,36 @@ class Program {
case 3:
Console.Clear();
for (int j = 0; j < dispensers.Length; j++) {
Console.WriteLine($"Dispenser {j + 1}:");
dispensers[j].StampaDispenser();
Console.WriteLine();
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++) {
Console.WriteLine($"Dispenser {j + 1}:");
dispensers[j].StampaDispenser();
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();
break;
}
@ -100,4 +120,24 @@ class Program {
Console.ReadKey();
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.AssemblyConfigurationAttribute("Debug")]
[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.AssemblyTitleAttribute("dispenser_sapone")]
[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