Last active
September 27, 2019 16:58
-
-
Save Grohden/ac19e74772a579e5643b4e9e1031c371 to your computer and use it in GitHub Desktop.
example java
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 Areas { | |
static class Retangulo { | |
protected int largura; | |
protected int altura; | |
Retangulo(int largura, int altura) { | |
this.largura = largura; | |
this.altura = altura; | |
} | |
public int getArea() { | |
return largura * altura; | |
} | |
} | |
static class Quadrado extends Retangulo { | |
Quadrado(int lado) { | |
super(lado, lado); | |
} | |
} | |
static class Cubo extends Quadrado { | |
private int dimensao; | |
Cubo(int dimensao) { | |
super(dimensao); | |
this.dimensao = dimensao; | |
} | |
@Override | |
public int getArea() { | |
return super.getArea() * dimensao; | |
} | |
} | |
public static void main(String[] args) { | |
Quadrado q = new Quadrado(4); | |
Retangulo r = new Retangulo(4, 8); | |
Cubo c = new Cubo(5); | |
System.out.println("area do quadrado: " + q.getArea()); | |
System.out.println("area do retangulo: " + r.getArea()); | |
System.out.println("area do cubo: " + c.getArea()); | |
} | |
} |
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 com.example; | |
public class Main { | |
enum Temperatura { | |
MINIMA, | |
MEDIA, | |
MAXIMA | |
} | |
static class Resistencia { | |
void liga() { | |
System.out.println("Resistencia ligada"); | |
} | |
void desliga() { | |
System.out.println("Resistencia desligada"); | |
} | |
} | |
static class Sensor { | |
Temperatura getTemperaturaAtual() { | |
return Temperatura.MINIMA; | |
} | |
} | |
static class Compressor { | |
int getTempoLigado() { | |
return 0; | |
} | |
void liga() { | |
System.out.println("Compressor ligado"); | |
} | |
void desliga() { | |
System.out.println("Compressor desligado"); | |
} | |
} | |
static class Ventilador { | |
void liga() { | |
System.out.println("Ventilador ligado"); | |
} | |
void desliga() { | |
System.out.println("Ventilador desligado"); | |
} | |
} | |
static class Freezer { | |
private Compressor compressor; | |
private Resistencia resistencia; | |
private Ventilador ventilador; | |
private Sensor sensor; | |
private Temperatura temperaturaConfigurada = Temperatura.MINIMA; | |
Freezer( | |
Compressor compressor, | |
Resistencia resistencia, | |
Ventilador ventilador, | |
Sensor sensor | |
) { | |
this.compressor = compressor; | |
this.resistencia = resistencia; | |
this.ventilador = ventilador; | |
this.sensor = sensor; | |
} | |
void configuraTemperatura(Temperatura temperatura) { | |
temperaturaConfigurada = temperatura; | |
ajustaControleDeTemperatura(); | |
} | |
void ajustaControleDeTemperatura() { | |
Temperatura atual = sensor.getTemperaturaAtual(); | |
int diferenca = atual.compareTo(temperaturaConfigurada); | |
if (diferenca > 0) { | |
ventilador.liga(); | |
compressor.liga(); | |
} else if (diferenca < 0) { | |
ventilador.desliga(); | |
compressor.desliga(); | |
} | |
checkCompressor(); | |
} | |
void checkCompressor() { | |
if (compressor.getTempoLigado() >= 8) { | |
compressor.desliga(); | |
ventilador.desliga(); | |
resistencia.liga(); | |
System.out.println("Iniciando degelo"); | |
// TODO: depois de 10 minutos reiniciar o processo com o ajustaControleDeTemperatura | |
} | |
} | |
} | |
public static void main(String[] args) { | |
Freezer freezer = new Freezer( | |
new Compressor(), | |
new Resistencia(), | |
new Ventilador(), | |
new Sensor() | |
); | |
freezer.configuraTemperatura(Temperatura.MAXIMA); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment