Created
September 14, 2022 07:49
-
-
Save ProfAndreaPollini/70bcb417e4b258d644ef4a584cebbb8f to your computer and use it in GitHub Desktop.
Lezione 14 09 2022
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() {} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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