Skip to content

Instantly share code, notes, and snippets.

@ProfAndreaPollini
Created September 14, 2022 07:49
Show Gist options
  • Save ProfAndreaPollini/70bcb417e4b258d644ef4a584cebbb8f to your computer and use it in GitHub Desktop.
Save ProfAndreaPollini/70bcb417e4b258d644ef4a584cebbb8f to your computer and use it in GitHub Desktop.
Lezione 14 09 2022
package test;
/**
*
* @author 15367519
*/
public class CassaAcustica {
private int volume;
public int getVolume() {
return volume;
}
public void setVolume(int volume) {
if (volume <= 100 && volume >=0) {
this.volume = volume;
}
}
}
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package test;
/**
*
* @author 15367519
*/
public class CassaAcusticaConPotenza {
private int volume;
private final int potenza;
public CassaAcusticaConPotenza(int pot) {
potenza = pot;
}
public int getPotenzaMassima() {
return potenza;
}
public int getPotenza() {
return potenza * volume / 100;
}
public int getVolume() {
return volume;
}
public void setVolume(int volume) {
if (volume <= 100 && volume >=0) {
this.volume = volume;
}
}
}
package test;
public class Telecomando {
private CassaAcusticaConPotenza cassaAcustica;
void connect(CassaAcusticaConPotenza cassa) {
cassaAcustica = cassa;
}
void alzaVolume() {
var v = cassaAcustica.getVolume();
cassaAcustica.setVolume(v+1);
}
void abbassaVolume() {}
}
package test;
/**
*
* @author 15367519
*/
public class Test {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
System.out.println("test");
var cassa = new CassaAcusticaConPotenza(80);
cassa.setVolume(90);
System.out.println("volume = " + cassa.getVolume());
System.out.println("potenza = " + cassa.getPotenza());
var telecomando = new Telecomando();
telecomando.connect(cassa);
telecomando.alzaVolume();
System.out.println("volume = " + cassa.getVolume());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment