Erogazioni
This commit is contained in:
parent
65ca5953b4
commit
68fce1e25d
60
Program.cs
60
Program.cs
@ -6,9 +6,7 @@ class Program {
|
|||||||
static void Main(string[] args) {
|
static void Main(string[] args) {
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
Rifornimento[] rifornimentos = CreaBenzinaio();
|
Rifornimento[] rifornimentos = CreaBenzinaio();
|
||||||
Random r = new();
|
(bool, double, double) rifornimento;
|
||||||
int indiceUltimaPompaBenzina = TrovaIndiceUltimaPompaBenzina(rifornimentos);
|
|
||||||
|
|
||||||
int scelta = 0;
|
int scelta = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
@ -26,10 +24,20 @@ class Program {
|
|||||||
case 0:
|
case 0:
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
|
rifornimento = RifornimentoBenzina(rifornimentos);
|
||||||
|
if (rifornimento.Item1) {
|
||||||
|
Console.WriteLine("Le pompe di benzina sono attualmente fuori servizio. È pregata di rieseguire il programma e riprovare.");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Console.WriteLine($"Benzina erogata: {rifornimento.Item2} L");
|
||||||
|
Console.WriteLine($"Costo: €{rifornimento.Item3}");
|
||||||
|
}
|
||||||
Pausa();
|
Pausa();
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
|
rifornimento = RifornimentoGasolio(rifornimentos);
|
||||||
|
Console.WriteLine($"Gasolio erogato: {rifornimento.Item2} L");
|
||||||
|
Console.WriteLine($"Costo: €{rifornimento.Item3}");
|
||||||
Pausa();
|
Pausa();
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
@ -56,13 +64,13 @@ class Program {
|
|||||||
|
|
||||||
static Rifornimento[] CreaBenzinaio() {
|
static Rifornimento[] CreaBenzinaio() {
|
||||||
Random r = new();
|
Random r = new();
|
||||||
int totalePompe = r.Next(1, 30);
|
int totalePompe = r.Next(1, 30); //limito il numero di pompe totali a 30 per evitare di usare 10 GB di RAM
|
||||||
int totaleBenzina = r.Next(totalePompe);
|
int totaleBenzina = r.Next(totalePompe); //creo un numero casuale di pompe di benzina. Se non ce ne sono, allora sono fuori servizio
|
||||||
Rifornimento[] ritorno = new Rifornimento[totalePompe];
|
Rifornimento[] ritorno = new Rifornimento[totalePompe];
|
||||||
for (int i = 0; i < totaleBenzina; i++) {
|
for (int i = 0; i < totaleBenzina; i++) {
|
||||||
ritorno[i] = new Rifornimento("benzina super", 1.885);
|
ritorno[i] = new Rifornimento("benzina super", 1.885);
|
||||||
}
|
}
|
||||||
for (int i = totaleBenzina; i < totalePompe; i++) {
|
for (int i = totaleBenzina; i < totalePompe; i++) {//riempio il resto dell'array con pompe di gasolio. Non possono essere fuori servizio
|
||||||
ritorno[i] = new Rifornimento("gasolio", 1.812);
|
ritorno[i] = new Rifornimento("gasolio", 1.812);
|
||||||
}
|
}
|
||||||
return ritorno;
|
return ritorno;
|
||||||
@ -78,4 +86,42 @@ class Program {
|
|||||||
}
|
}
|
||||||
return i - 2;
|
return i - 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static (bool, double, double) RifornimentoBenzina(Rifornimento[] p_rifornimentos) {
|
||||||
|
(bool, double, double) ritorno;
|
||||||
|
Random r = new();
|
||||||
|
int indiceUltimaPompaBenzina = TrovaIndiceUltimaPompaBenzina(p_rifornimentos);
|
||||||
|
int indicePompaInUso = r.Next(indiceUltimaPompaBenzina + 1);
|
||||||
|
(double, double) erogazione;
|
||||||
|
|
||||||
|
if (indiceUltimaPompaBenzina < 0) {
|
||||||
|
//pompe di benzina fuori servizio
|
||||||
|
ritorno.Item1 = true;
|
||||||
|
ritorno.Item2 = 0;
|
||||||
|
ritorno.Item3 = 0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
erogazione = p_rifornimentos[indicePompaInUso].Erogazione();
|
||||||
|
ritorno.Item1 = false;
|
||||||
|
ritorno.Item2 = erogazione.Item1;
|
||||||
|
ritorno.Item3 = erogazione.Item2;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ritorno;
|
||||||
|
}
|
||||||
|
|
||||||
|
static (bool, double, double) RifornimentoGasolio(Rifornimento[] p_rifornimentos) {
|
||||||
|
(double, double) erogazione;
|
||||||
|
(bool, double, double) ritorno;
|
||||||
|
Random r = new();
|
||||||
|
int indiceUltimaPompaBenzina = TrovaIndiceUltimaPompaBenzina(p_rifornimentos);
|
||||||
|
|
||||||
|
erogazione = p_rifornimentos[r.Next(indiceUltimaPompaBenzina + 1, p_rifornimentos.Length)].Erogazione();
|
||||||
|
|
||||||
|
ritorno.Item1 = false;
|
||||||
|
ritorno.Item2 = erogazione.Item1;
|
||||||
|
ritorno.Item3 = erogazione.Item2;
|
||||||
|
|
||||||
|
return ritorno;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,21 +2,23 @@ namespace vacanzeEstive_benzinaio;
|
|||||||
|
|
||||||
class Rifornimento {
|
class Rifornimento {
|
||||||
|
|
||||||
string tipoCarburante;
|
readonly string tipoCarburante;
|
||||||
double litriErogatiComplessivi = 0;
|
double litriErogatiComplessivi = 0;
|
||||||
double costoComplessivo = 0;
|
double costoComplessivo = 0;
|
||||||
double costoAlLitro;
|
readonly double costoAlLitro;
|
||||||
|
|
||||||
public Rifornimento(string p_tipoCarburante, double p_costoAlLitro) {
|
public Rifornimento(string p_tipoCarburante, double p_costoAlLitro) {
|
||||||
this.tipoCarburante = p_tipoCarburante;
|
this.tipoCarburante = p_tipoCarburante;
|
||||||
this.costoAlLitro = p_costoAlLitro;
|
this.costoAlLitro = p_costoAlLitro;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double Erogazione() {
|
public (double, double) Erogazione() {
|
||||||
Random r = new();
|
Random r = new();
|
||||||
double ritorno = r.Next(1, 30) + r.NextDouble();
|
(double, double) ritorno;
|
||||||
this.litriErogatiComplessivi += ritorno;
|
ritorno.Item1 = double.Round(r.Next(1, 30) + r.NextDouble(), 3); //arrotonda l'erogazione casuale a 3 cifre decimali
|
||||||
this.costoComplessivo += ritorno * costoAlLitro;
|
ritorno.Item2 = double.Round(ritorno.Item1 * costoAlLitro, 2); //arrotonda il costo a 2 cifre decimali
|
||||||
|
this.litriErogatiComplessivi += ritorno.Item1;
|
||||||
|
this.costoComplessivo = ritorno.Item2;
|
||||||
return ritorno;
|
return ritorno;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -13,7 +13,7 @@ using System.Reflection;
|
|||||||
[assembly: System.Reflection.AssemblyCompanyAttribute("vacanzeEstive_benzinaio")]
|
[assembly: System.Reflection.AssemblyCompanyAttribute("vacanzeEstive_benzinaio")]
|
||||||
[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+66abb93ec7d368cd60d47c8892b1d7163d386477")]
|
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+65ca5953b465607bd2914b089ffb227096216243")]
|
||||||
[assembly: System.Reflection.AssemblyProductAttribute("vacanzeEstive_benzinaio")]
|
[assembly: System.Reflection.AssemblyProductAttribute("vacanzeEstive_benzinaio")]
|
||||||
[assembly: System.Reflection.AssemblyTitleAttribute("vacanzeEstive_benzinaio")]
|
[assembly: System.Reflection.AssemblyTitleAttribute("vacanzeEstive_benzinaio")]
|
||||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
8fbc40964bd836344ae2e0f035a3687ced9a797d3d0a6c1ea33335f3a20553df
|
e582eb33653bc9c49a63e51e76550ffc23d095b9a773769a24b4e149c0e6f14a
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user