83 lines
2.4 KiB
C#
83 lines
2.4 KiB
C#
namespace dispenser_sapone;
|
|
|
|
class Dispenser {
|
|
string tipologia;
|
|
double capienza;
|
|
double quantitàErogata;
|
|
double quantitàContenuta;
|
|
|
|
//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;
|
|
}
|
|
|
|
public void SetQuantitàErogata(double p_quantitàErogata) {
|
|
this.quantitàErogata = p_quantitàErogata;
|
|
}
|
|
|
|
public string GetTipologia() {
|
|
return this.tipologia;
|
|
}
|
|
|
|
public double GetQuantitàErogata() {
|
|
return this.quantitàErogata;
|
|
}
|
|
|
|
public double GetCapienza() {
|
|
return this.capienza;
|
|
}
|
|
|
|
public double GetQuantitàContenuta() {
|
|
return this.quantitàContenuta;
|
|
}
|
|
|
|
public void StampaDispenser() {
|
|
Console.WriteLine($"Tipologia: {this.GetTipologia()}");
|
|
Console.WriteLine($"Capienza: {this.GetCapienza()}");
|
|
Console.WriteLine($"Quantità erogata: {this.GetQuantitàErogata()}");
|
|
Console.WriteLine($"Quantità contenuta: {this.GetQuantitàContenuta()}");
|
|
}
|
|
|
|
public double Erogazione() {
|
|
double ritorno;
|
|
if (this.quantitàContenuta - this.quantitàErogata < 0) {
|
|
ritorno = 0;
|
|
}
|
|
else {
|
|
this.quantitàContenuta = this.quantitàContenuta - this.quantitàErogata;
|
|
ritorno = this.quantitàContenuta;
|
|
}
|
|
return ritorno;
|
|
}
|
|
|
|
public (double, bool) Riempimento(double p_refill) {
|
|
double ritorno;
|
|
bool overflow;
|
|
if (this.quantitàContenuta + p_refill > this.capienza) {
|
|
this.quantitàContenuta = this.capienza;
|
|
ritorno = this.quantitàContenuta + p_refill - this.capienza;
|
|
overflow = true;
|
|
}
|
|
else {
|
|
this.quantitàContenuta = this.quantitàContenuta + p_refill;
|
|
ritorno = this.quantitàContenuta;
|
|
overflow = false;
|
|
}
|
|
return (ritorno, overflow);
|
|
}
|
|
} |