Last active
April 28, 2019 18:02
-
-
Save lucas404x/b334fd70eb2683d09ee6a2aa5e36c089 to your computer and use it in GitHub Desktop.
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
/** | |
* Autor: José Lucas | |
* Arquivo: ExecucaoTeste.java | |
* Descricao: Programa para praticar o uso de classes e objetos | |
* Aula: PROO – Lab3 | |
* | |
**/ | |
import classes.Musica; | |
import classes.Retangulo; | |
public class ExecucaoTeste { | |
public static void main(String[] args) { | |
Retangulo retangulo1 = new Retangulo(2, 4, "Azul"); | |
Retangulo retangulo2 = new Retangulo(1.4, 3.4, "Vermelho"); | |
Musica musica1 = new Musica(true, true, false); | |
Musica musica2 = new Musica(false, true, false); | |
musica1.cantando(false); | |
musica1.dancando(true); | |
musica1.tocando(false); | |
System.out.println("***********"); | |
musica2.cantando(true); | |
musica2.dancando(false); | |
musica2.tocando(true); | |
System.out.println("***********"); | |
retangulo1.setAltura(-4); | |
retangulo2.setLado(-9); | |
System.out.println(retangulo1.toString()); | |
System.out.println(retangulo2.toString()); | |
System.out.println("***********"); | |
} | |
} |
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
/** | |
* Autor: José Lucas | |
* Arquivo: Musica.java | |
* Descricao: Programa para praticar o uso de classes e objetos | |
* Aula: PROO – Lab3 | |
* | |
**/ | |
package classes; | |
//Classe abstrata | |
public class Musica { | |
public boolean cantar, dancar, tocar; | |
public Musica(){ | |
} | |
public Musica(boolean cantar, boolean dancar, boolean tocar) { | |
this.cantar = cantar; | |
this.dancar = dancar; | |
this.tocar = tocar; | |
} | |
public void cantando(boolean cantar) { | |
if (cantar == false) { | |
System.out.println("Parando de cantar!"); | |
} | |
else if(this.cantar == false && cantar) { | |
System.out.println("LALALALALA"); | |
} | |
else { | |
System.out.println("Erro, o valor já é true"); | |
} | |
} | |
public void dancando(boolean dancar) { | |
if(dancar == false) { | |
System.out.println("Parando de dançar!"); | |
} | |
else if(this.dancar == false && dancar) { | |
System.out.println("DANÇANDO, DANÇANDO, DANÇANDO"); | |
} | |
else { | |
System.out.println("Erro, o valor já é true"); | |
} | |
} | |
public void tocando(boolean tocar) { | |
if(tocar == false) { | |
System.out.println("Parando de tocar!"); | |
} | |
else if(this.tocar == false && tocar) { | |
System.out.println("***Tocando algum instrumento***"); | |
} | |
else { | |
System.out.println("Erro, o valor já é true"); | |
} | |
} | |
} |
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
/** | |
* Autor: José Lucas | |
* Arquivo: Retangulo.java | |
* Descricao: Programa para praticar o uso de classes e objetos | |
* Aula: PROO – Lab3 | |
* | |
**/ | |
package classes; | |
//Classe concreta | |
public class Retangulo { | |
private double lado, altura; | |
private String cor; | |
public Retangulo() { | |
} | |
public Retangulo(double lado, double altura, String cor) { | |
this.lado = lado; | |
this.altura = altura; | |
this.cor = cor; | |
} | |
public double getLado() { | |
return lado; | |
} | |
public void setLado(double lado) { | |
if(lado < 0) { | |
System.out.println("Valor invalido!"); | |
} | |
else { | |
this.lado = lado; | |
} | |
} | |
public double getAltura() { | |
return altura; | |
} | |
public void setAltura(double altura) { | |
if(altura < 0) { | |
System.out.println("Valor invalido!"); | |
} | |
else { | |
this.altura = altura; | |
} | |
} | |
public String getCor() { | |
return cor; | |
} | |
public void setCor(String cor) { | |
this.cor = cor; | |
} | |
public double calculaArea() { | |
return this.altura * this.lado; | |
} | |
public String toString() { | |
return "Retangulo [lado=" + lado + ", altura=" + altura + ", cor=" + cor + ", área: " + this.calculaArea() + "]"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment