Last active
August 29, 2015 14:06
-
-
Save flaviacs/6b4db82b9f77d1eef634 to your computer and use it in GitHub Desktop.
Aula Ciro - 25-09-14 // cont. -- Equipamento
This file contains hidden or 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
| 2ª Lista de Exercícios | |
| Implemente as classes mostradas no diagrama de classes UML abaixo: | |
| ____________________________________ | |
| | Equipamento | | |
| |------------------------------------| | |
| |- ligado : boolean | | |
| |------------------------------------| | |
| |+ equipamento(ligado : boolean) | | |
| |+ ligar() : VOID | | |
| |+ desligar() : VOID | | |
| |+ toString() : VOID | | |
| |____________________________________| | |
| ^ | |
| | | |
| | | |
| ______________________________________________________________________ | |
| | EquipamentoSonoro | | |
| |----------------------------------------------------------------------| | |
| |- stereo : boolean | | |
| |- volume : int | | |
| |----------------------------------------------------------------------| | |
| |+ EquipamentoSonoro(ligado : boolean, stereo : boolean, volume : int) | | |
| |+ ligar() : VOID | | |
| |+ mono() : VOID | | |
| |+ stereo() : VOID | | |
| |+ aumentarVolume() : VOID | | |
| |+ diminuirVolume() : VOID | | |
| |+ toString() : String | | |
| |______________________________________________________________________| | |
| ______________________________________________________________ | |
| | | | |
| | http://fatecrl.edu.br/moodle/mod/resource/view.php?id=3816 | | |
| |______________________________________________________________| |
This file contains hidden or 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 equipamento; | |
| public class Equipamento { | |
| private boolean ligado; | |
| public Equipamento(boolean ligado){ | |
| this.ligado = ligado; | |
| } | |
| public void ligar(){ | |
| ligado = true; | |
| } | |
| public void desligar(){ | |
| ligado = false; | |
| } | |
| public String toString(){ | |
| return "Equipamento" + (ligado ? " ligado" : " desligado"); //if ternário | |
| //return "O equipamento está:" + ligado; | |
| } | |
| } |
This file contains hidden or 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
| public class EquipamentoSonoro extends Equipamento { | |
| private boolean stereo; | |
| private int volume; | |
| public EquipamentoSonoro(boolean ligado,boolean stereo,int volume){//construtor padrão | |
| super(ligado); | |
| this.stereo = stereo; | |
| this.volume = volume; | |
| } | |
| public void mono(){ | |
| stereo = false; | |
| } | |
| public void stereo(){ | |
| stereo = true; | |
| } | |
| public void ligar(){ | |
| super.ligar(); | |
| volume = 5 ; | |
| } | |
| public String toString() { | |
| return super.toString() + " Volume: " + volume +" Stereo:"+ (stereo ? " ligado" : " desligado"); | |
| } | |
| public void aumentarVolume(){ | |
| if (volume < 10){ | |
| volume = volume + 1; | |
| }else{ | |
| System.out.println("O volume já está no máximo!"); | |
| } | |
| } | |
| public void diminuirVolume(){ | |
| if (volume != 0){ | |
| volume = volume - 1; | |
| }else{ | |
| System.out.println("O volume já está totalmente diminuido!"); | |
| } | |
| } | |
| } |
This file contains hidden or 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
| public class MainEquipamento { | |
| public static void main(String[] args) { | |
| Equipamento e = new Equipamento(true); | |
| e.desligar(); | |
| e.ligar(); | |
| e.desligar(); | |
| System.out.println(e.toString()); | |
| } | |
| } |
This file contains hidden or 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
| public class MainEquipamentoSonoro { | |
| public static void main(String[] args) { | |
| EquipamentoSonoro radio = new EquipamentoSonoro(false, true, 2); | |
| System.out.println(radio); | |
| radio.ligar(); | |
| radio.mono(); | |
| radio.aumentarVolume(); | |
| radio.aumentarVolume(); | |
| radio.aumentarVolume(); | |
| radio.diminuirVolume(); | |
| radio.stereo(); | |
| System.out.println(radio); | |
| radio.desligar(); | |
| System.out.println(radio); | |
| } | |
| } |
Author
Author
Continuação da aula do DIA 25/09/2014
https://gist.github.com/flaviacs/4c17b8b38c8cd4d6be94
https://gist.github.com/flaviacs/9c1bcb68a40f58137d35
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Trabalho:
moodle: http://fatecrl.edu.br/moodle/mod/resource/view.php?id=3901