Metodi classe

This commit is contained in:
La Programmatrice Verde 2025-04-18 12:55:33 +02:00
parent 5b11eed20b
commit 16b04931c6
2 changed files with 55 additions and 10 deletions

View File

@ -1,5 +1,54 @@
namespace biblioteca;
class Libro {
string nome;
double prezzo;
string numeroScaffale;
string numeroPagine;
string casaEditrice;
public Libro(string p_nome, double p_prezzo, string p_numeroScaffale, string p_numeroPagine, string p_casaEditrice) {
this.nome = p_nome;
this.prezzo = p_prezzo;
this.numeroScaffale = p_numeroScaffale;
this.numeroPagine = p_numeroPagine;
this.casaEditrice = p_casaEditrice;
}
public string GetNome() {
return this.nome;
}
public double GetPrezzo() {
return this.prezzo;
}
public string GetNumeroScaffale() {
return this.numeroScaffale;
}
public string GetNumeroPagine() {
return this.numeroPagine;
}
public string GetCasaEditrice() {
return this.casaEditrice;
}
public void SetPrezzo(double p_prezzo) {
this.prezzo = p_prezzo;
}
public void StampaLibro() {
Console.WriteLine($"Nome: {this.GetNome()}");
Console.WriteLine($"Prezzo: {this.GetPrezzo()}");
Console.WriteLine($"Numero scaffale: {this.GetNumeroScaffale()}");
Console.WriteLine($"Numero pagine: {this.GetNumeroPagine()}");
Console.WriteLine($"Casa editrice: {this.GetCasaEditrice()}");
}
public void ApplicaSconto() {
const double SCONTO = 0.1;
this.SetPrezzo(this.GetPrezzo() - this.GetPrezzo() * SCONTO);
}
}

View File

@ -3,9 +3,9 @@
class Program {
static void Main(string[] args) {
Console.Clear();
double quantitàErogata, quantitàContenuta, capienza, quantitàRimasta, quantitàRiempimento;
const int MAX_LIBRI = 10;
int scelta, input, i = 0;
Dispenser[] dispensers;
Libro[] biblioteca= new Libro[MAX_LIBRI];
bool oggettoEsistente;
(double, bool) ritornoRiempimento;
Dispenser elementoRiempimento;
@ -29,14 +29,10 @@ class Program {
break;
case 1:
Console.Clear();
if (i > dispensers.Length - 1) {
Console.WriteLine($"Errore: non si possono creare più di {dispensers.Length} dispensers.");
}
else {
dispensers[i] = new Dispenser();
i++;
Console.WriteLine("Dispenser standard creato.");
}
dispensers[i] = new Dispenser();
i++;
Console.WriteLine("Dispenser standard creato.");
Pausa();
break;
case 2: