diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e10e727 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/.metadata/ diff --git a/bin/br/com/codar/maquinacafe/AguaQuente.class b/bin/br/com/codar/maquinacafe/AguaQuente.class new file mode 100644 index 0000000..6d7820d Binary files /dev/null and b/bin/br/com/codar/maquinacafe/AguaQuente.class differ diff --git a/bin/br/com/codar/maquinacafe/Bebida.class b/bin/br/com/codar/maquinacafe/Bebida.class new file mode 100644 index 0000000..72b0bcc Binary files /dev/null and b/bin/br/com/codar/maquinacafe/Bebida.class differ diff --git a/bin/br/com/codar/maquinacafe/Cafe.class b/bin/br/com/codar/maquinacafe/Cafe.class new file mode 100644 index 0000000..a668d20 Binary files /dev/null and b/bin/br/com/codar/maquinacafe/Cafe.class differ diff --git a/bin/br/com/codar/maquinacafe/CafeComLeite.class b/bin/br/com/codar/maquinacafe/CafeComLeite.class new file mode 100644 index 0000000..af3893a Binary files /dev/null and b/bin/br/com/codar/maquinacafe/CafeComLeite.class differ diff --git a/bin/br/com/codar/maquinacafe/Cafeteira.class b/bin/br/com/codar/maquinacafe/Cafeteira.class new file mode 100644 index 0000000..8001fcf Binary files /dev/null and b/bin/br/com/codar/maquinacafe/Cafeteira.class differ diff --git a/bin/br/com/codar/maquinacafe/Capuccino.class b/bin/br/com/codar/maquinacafe/Capuccino.class new file mode 100644 index 0000000..430a6f5 Binary files /dev/null and b/bin/br/com/codar/maquinacafe/Capuccino.class differ diff --git a/bin/br/com/codar/maquinacafe/ChaDeLimao.class b/bin/br/com/codar/maquinacafe/ChaDeLimao.class new file mode 100644 index 0000000..a93dd6b Binary files /dev/null and b/bin/br/com/codar/maquinacafe/ChaDeLimao.class differ diff --git a/bin/br/com/codar/maquinacafe/Credito.class b/bin/br/com/codar/maquinacafe/Credito.class new file mode 100644 index 0000000..cc773d1 Binary files /dev/null and b/bin/br/com/codar/maquinacafe/Credito.class differ diff --git a/bin/br/com/codar/maquinacafe/Pedido.class b/bin/br/com/codar/maquinacafe/Pedido.class new file mode 100644 index 0000000..34ed3b9 Binary files /dev/null and b/bin/br/com/codar/maquinacafe/Pedido.class differ diff --git a/bin/br/com/codar/maquinacafe/ReservatorioAgua.class b/bin/br/com/codar/maquinacafe/ReservatorioAgua.class new file mode 100644 index 0000000..7f3744f Binary files /dev/null and b/bin/br/com/codar/maquinacafe/ReservatorioAgua.class differ diff --git a/bin/br/com/codar/maquinacafe/tdd/CreditoTeste.class b/bin/br/com/codar/maquinacafe/tdd/CreditoTeste.class new file mode 100644 index 0000000..5659184 Binary files /dev/null and b/bin/br/com/codar/maquinacafe/tdd/CreditoTeste.class differ diff --git a/bin/br/com/codar/maquinacafe/tdd/ReservatorioAguaTeste.class b/bin/br/com/codar/maquinacafe/tdd/ReservatorioAguaTeste.class new file mode 100644 index 0000000..0966acb Binary files /dev/null and b/bin/br/com/codar/maquinacafe/tdd/ReservatorioAguaTeste.class differ diff --git a/src/br/com/codar/maquinacafe/AguaQuente.java b/src/br/com/codar/maquinacafe/AguaQuente.java new file mode 100644 index 0000000..ecb8f23 --- /dev/null +++ b/src/br/com/codar/maquinacafe/AguaQuente.java @@ -0,0 +1,30 @@ +package br.com.codar.maquinacafe; + +import java.util.Scanner; + +public class AguaQuente implements Bebida { + + private double preco; + private int aguaConsumida; + + public AguaQuente(int pedidoBebidaUsuario) { + } + + public void preparaBebida(Credito credito, ReservatorioAgua reservatorio) { + System.out.println("Água Quente é gratuito, obrigado pelo pedido."); + } + + public int solicitaNivelAcucar() { + return 0; + } + + @Override + public double getPreco() { + return 0; + } + + @Override + public int getAguaConsumida() { + return 50; + } +} \ No newline at end of file diff --git a/src/br/com/codar/maquinacafe/Bebida.java b/src/br/com/codar/maquinacafe/Bebida.java new file mode 100644 index 0000000..97d5862 --- /dev/null +++ b/src/br/com/codar/maquinacafe/Bebida.java @@ -0,0 +1,28 @@ +package br.com.codar.maquinacafe; + +import java.util.Scanner; + +public interface Bebida { + + public default void preparaBebida(Credito credito, ReservatorioAgua reservatorio) { + if (credito.getValorCredito() < this.getPreco()) { + System.out.println("Valor de crédito insuficiente. Você pode inserir mais créditos agora"); + credito.adicionaCredito(credito); + } + reservatorio.conferindoReservatorio(); + reservatorio.utilizandoAgua(getAguaConsumida()); + } + + public default int solicitaNivelAcucar() { + Scanner nivelAcucar = new Scanner(System.in); + System.out.println("Como padrão, o nível de açúcar será 3, qual nível gostaria?\n " + "0, 1, 2, 3, 4, 5"); + + int opcaoAcucar = nivelAcucar.nextInt(); + + return opcaoAcucar; + } + + double getPreco(); + + int getAguaConsumida(); +} diff --git a/src/br/com/codar/maquinacafe/Cafe.java b/src/br/com/codar/maquinacafe/Cafe.java new file mode 100644 index 0000000..b24beac --- /dev/null +++ b/src/br/com/codar/maquinacafe/Cafe.java @@ -0,0 +1,30 @@ +package br.com.codar.maquinacafe; + +import java.util.Scanner; + +public class Cafe implements Bebida { + + private double preco; + private int aguaConsumida; + + public Cafe(int pedidoBebidaUsuario) { + } + + public void preparaBebida(Credito credito, ReservatorioAgua reservatorio) { + } + + public int solicitaNivelAcucar() { + return solicitaNivelAcucar(); + } + + @Override + public double getPreco() { + return 0.50; + } + + @Override + public int getAguaConsumida() { + return 50; + } + +} \ No newline at end of file diff --git a/src/br/com/codar/maquinacafe/CafeComLeite.java b/src/br/com/codar/maquinacafe/CafeComLeite.java new file mode 100644 index 0000000..288fbcb --- /dev/null +++ b/src/br/com/codar/maquinacafe/CafeComLeite.java @@ -0,0 +1,29 @@ +package br.com.codar.maquinacafe; + +import java.util.Scanner; + +public class CafeComLeite implements Bebida { + + private double preco; + private int aguaConsumida; + + public CafeComLeite(int pedidoBebidaUsuario) { + } + + public void preparaBebida(Credito credito, ReservatorioAgua reservatorio) { + } + + public int solicitaNivelAcucar() { + return solicitaNivelAcucar(); + } + + @Override + public double getPreco() { + return 1.00; + } + + @Override + public int getAguaConsumida() { + return 50; + } +} \ No newline at end of file diff --git a/src/br/com/codar/maquinacafe/Cafeteira.java b/src/br/com/codar/maquinacafe/Cafeteira.java new file mode 100644 index 0000000..c60c23d --- /dev/null +++ b/src/br/com/codar/maquinacafe/Cafeteira.java @@ -0,0 +1,45 @@ +package br.com.codar.maquinacafe; + +import java.util.Scanner; + +public class Cafeteira { + + public static void main(String[] args) { + + Pedido pedido = new Pedido(); + Credito credito = new Credito(); + int iniciarEscolha; + + Scanner pedidoInicial = new Scanner(System.in); + System.out.println("Olá, escolha uma das opções abaixo\n" + "1 - Adicionar créditos\n" + "2 - Realizar pedido"); + + iniciarEscolha = pedidoInicial.nextInt(); + System.out.println("Você escolheu: " + iniciarEscolha); + + switch (iniciarEscolha) { + case 1: + credito.adicionaCredito(credito); + case 2: + pedido.realizarPedido(credito, null); + break; + } + + Scanner outroPedido = new Scanner(System.in); + System.out.println("Gostaria de fazer mais um pedido?\n" + "1 - Sim\n" + "2 - Não"); + + iniciarEscolha = outroPedido.nextInt(); + System.out.println("Você escolheu: " + iniciarEscolha); + + switch (iniciarEscolha) { + case 1: + credito.adicionaCredito(credito); + pedido.realizarPedido(credito, null); + break; + case 2: + System.out.println("Obrigado e até mais."); + break; + } + } +} + +//Desenvolvido por Gabriel Trudes Melo \ No newline at end of file diff --git a/src/br/com/codar/maquinacafe/Capuccino.java b/src/br/com/codar/maquinacafe/Capuccino.java new file mode 100644 index 0000000..44f5dff --- /dev/null +++ b/src/br/com/codar/maquinacafe/Capuccino.java @@ -0,0 +1,29 @@ +package br.com.codar.maquinacafe; + +import java.util.Scanner; + +public class Capuccino implements Bebida { + + private double preco; + private int aguaConsumida; + + public Capuccino(int pedidoBebidaUsuario) { + } + + public void preparaBebida(Credito credito, ReservatorioAgua reservatorio) { + } + + public int solicitaNivelAcucar() { + return solicitaNivelAcucar(); + } + + @Override + public double getPreco() { + return 1.50; + } + + @Override + public int getAguaConsumida() { + return 50; + } +} \ No newline at end of file diff --git a/src/br/com/codar/maquinacafe/ChaDeLimao.java b/src/br/com/codar/maquinacafe/ChaDeLimao.java new file mode 100644 index 0000000..f9f9ccc --- /dev/null +++ b/src/br/com/codar/maquinacafe/ChaDeLimao.java @@ -0,0 +1,29 @@ +package br.com.codar.maquinacafe; + +import java.util.Scanner; + +public class ChaDeLimao implements Bebida { + + private double preco; + private int aguaConsumida; + + public ChaDeLimao(int pedidoBebidaUsuario) { + } + + public void preparaBebida(Credito credito, ReservatorioAgua reservatorio) { + } + + public int solicitaNivelAcucar() { + return solicitaNivelAcucar(); + } + + @Override + public double getPreco() { + return 1.00; + } + + @Override + public int getAguaConsumida() { + return 50; + } +} \ No newline at end of file diff --git a/src/br/com/codar/maquinacafe/Credito.java b/src/br/com/codar/maquinacafe/Credito.java new file mode 100644 index 0000000..237d826 --- /dev/null +++ b/src/br/com/codar/maquinacafe/Credito.java @@ -0,0 +1,52 @@ +package br.com.codar.maquinacafe; + +import java.io.InputStream; +import java.util.Scanner; + +public class Credito { + + private double valorCredito; + + + double getValorCredito() { + return valorCredito; + } + + public void setValorCredito(double valorCredito) { + this.valorCredito++; + } + + public InputStream adicionaCredito(Credito credito) { + Scanner opcaoCredito = new Scanner(System.in); + System.out.println("Entre com o valor do crédito disponível:\n" + + "5 - 5 créditos\n" + + "10 - 10 créditos\n" + + "20 - 20 créditos\n" + + "50 - 50 créditos\n" + + "100 - 100 créditos\n" + + "200 - 200 créditos"); + + int creditoInserido = opcaoCredito.nextInt(); + if (creditoInserido <= 0) { + throw new IllegalArgumentException("Insira um valor valido"); + } + double valorCredito = credito.getValorCredito(); + valorCredito += creditoInserido; + credito.setValorCredito(valorCredito); + return null; + + } + + public void calculaTroco(double valorBebida, Credito credito) { + double valorCredito = credito.getValorCredito(); + valorCredito -= valorBebida; + credito.setValorCredito(valorCredito); + + Scanner troco = new Scanner(System.in); + System.out.println("Troco em créditos: " + valorCredito); + + valorCredito = 0; + credito.setValorCredito(valorCredito); + } + +} \ No newline at end of file diff --git a/src/br/com/codar/maquinacafe/Pedido.java b/src/br/com/codar/maquinacafe/Pedido.java new file mode 100644 index 0000000..5bfd116 --- /dev/null +++ b/src/br/com/codar/maquinacafe/Pedido.java @@ -0,0 +1,52 @@ +package br.com.codar.maquinacafe; + +import java.util.Scanner; + +public class Pedido { + + public void realizarPedido(Credito credito, ReservatorioAgua reservatorio) { + Scanner opcaoBebida = new Scanner(System.in); + System.out.println( + "Faça seu pedido entre as opções:\n" + "1 - Café por R$0.50\n" + "2 - Café Com Leite por R$1.00\n" + + "3 - Capuccino por R$1.50\n" + "4 - Chá De Limão por R$1.00\n" + "5 - Água quente GRATUITO"); + + int pedidoBebidaUsuario = opcaoBebida.nextInt(); + System.out.println("Obrigado, seu pedido será: " + pedidoBebidaUsuario); + + switch (pedidoBebidaUsuario) { + case 1: + Cafe cafe = new Cafe(pedidoBebidaUsuario); + cafe.preparaBebida(credito, reservatorio); + credito.calculaTroco(cafe.getPreco(), credito); + break; + + case 2: + CafeComLeite cafeComLeite = new CafeComLeite(pedidoBebidaUsuario); + cafeComLeite.preparaBebida(credito, reservatorio); + credito.calculaTroco(cafeComLeite.getPreco(), credito); + break; + + case 3: + Capuccino capuccino = new Capuccino(pedidoBebidaUsuario); + capuccino.preparaBebida(credito, reservatorio); + credito.calculaTroco(capuccino.getPreco(), credito); + break; + + case 4: + ChaDeLimao chaDeLimao = new ChaDeLimao(pedidoBebidaUsuario); + chaDeLimao.preparaBebida(credito, reservatorio); + credito.calculaTroco(chaDeLimao.getPreco(), credito); + break; + + case 5: + AguaQuente aguaQuente = new AguaQuente(pedidoBebidaUsuario); + aguaQuente.preparaBebida(credito, reservatorio); + credito.calculaTroco(aguaQuente.getPreco(), credito); + break; + + default: + System.out.println("Entre com uma das opções disponíveis"); + } + } + +} diff --git a/src/br/com/codar/maquinacafe/ReservatorioAgua.java b/src/br/com/codar/maquinacafe/ReservatorioAgua.java new file mode 100644 index 0000000..022bfdc --- /dev/null +++ b/src/br/com/codar/maquinacafe/ReservatorioAgua.java @@ -0,0 +1,41 @@ +package br.com.codar.maquinacafe; + +public class ReservatorioAgua { + + private int nivelAgua; + private int reservatorio; + + public int getNivelAgua() { + return nivelAgua; + } + + public void setNivelAgua(int nivelAgua) { + this.nivelAgua = nivelAgua; + } + + public int getReservatorio() { + return reservatorio; + } + + public void conferindoReservatorio() { + int reservatorio = getNivelAgua(); + + if (reservatorio == 0) { + abastecendoReservatorio(); + } + } + + public int utilizandoAgua(int aguaConsumida) { + int nivelAgua = getNivelAgua(); + nivelAgua -= aguaConsumida; + setNivelAgua(nivelAgua); + + return nivelAgua; + } + + public void abastecendoReservatorio() { + setNivelAgua(1000); + int reservatorio = getNivelAgua(); + } + +} \ No newline at end of file diff --git a/src/br/com/codar/maquinacafe/tdd/CreditoTeste.java b/src/br/com/codar/maquinacafe/tdd/CreditoTeste.java new file mode 100644 index 0000000..9a795bc --- /dev/null +++ b/src/br/com/codar/maquinacafe/tdd/CreditoTeste.java @@ -0,0 +1,32 @@ +package br.com.codar.maquinacafe.tdd; + +import static org.junit.Assert.assertThrows; + +import java.io.InputStream; + +import org.junit.jupiter.api.Test; + +import br.com.codar.maquinacafe.Credito; + +public class CreditoTeste { + + @Test + public void deveriaAdicionarCreditoEDevolverTroco() { + Credito input = new Credito(); + + InputStream valorCredito = input.adicionaCredito(input); + + input.adicionaCredito(input); + input.calculaTroco(0, input); + + } + + @Test + public void deveriaChamarExceptionQuandoCreditoAdicionadoIgualOuMenorAZero() { + Credito input = new Credito(); + + assertThrows(IllegalArgumentException.class, () -> input.adicionaCredito(input)); + + } + +} \ No newline at end of file diff --git a/src/br/com/codar/maquinacafe/tdd/ReservatorioAguaTeste.java b/src/br/com/codar/maquinacafe/tdd/ReservatorioAguaTeste.java new file mode 100644 index 0000000..c8deb29 --- /dev/null +++ b/src/br/com/codar/maquinacafe/tdd/ReservatorioAguaTeste.java @@ -0,0 +1,21 @@ +package br.com.codar.maquinacafe.tdd; + +import static org.junit.Assert.assertEquals; + +import org.junit.jupiter.api.Test; + +import br.com.codar.maquinacafe.ReservatorioAgua; + +public class ReservatorioAguaTeste { + + @Test + public void deveriaAbastecerReservatorio() { + ReservatorioAgua reservatorio = new ReservatorioAgua(); + reservatorio.abastecendoReservatorio(); + + int aguaConsumida = reservatorio.utilizandoAgua(50); + + assertEquals(950, aguaConsumida); + } + +} \ No newline at end of file