Skip to content

Desafio atualizado#4

Open
lilianjaf wants to merge 9 commits into
movimentocodar:mainfrom
lilianjaf:main
Open

Desafio atualizado#4
lilianjaf wants to merge 9 commits into
movimentocodar:mainfrom
lilianjaf:main

Conversation

@lilianjaf
Copy link
Copy Markdown

No description provided.

Comment thread .idea/.gitignore
@@ -0,0 +1,3 @@
# Default ignored files
/shelf/
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

É uma boa prática ignorar os arquivos/pastas:

  • .idea
  • out/

Comment thread src/cafes/Acucar.java Outdated
package cafes;

public enum Acucar {
Nivel0("nenhuma"),Nivel1("pouquíssima"),Nivel2("pouca"),Nivel3("normal"),Nivel4("muito"),Nivel5("bastante");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a descrição dos campos do enum poderia seguir o mesmo que vc fez com o campo quantidadeDeAcucar (que poderia chamar descrição ao invés de quantidade, quantidade me remete a um número, o que acha?)

Uma convenção de nomenclatura para campos de enum é seguir o padrão UPPER_CASE, então poderia ser, por exemplo, NIVEL_0 ou NENHUMA, e assim por diante

Comment thread src/cafes/Bebida.java Outdated
public class Bebida {
private int id;
private String nome;
Receitas receita;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Uma bebida tem várias Receitas? O nome da classe Receitas ficou no plural errado ou a ideia foi deixar uma classe com todas as Receitas mesmo?
  • Pq a visibilidade é default e não private?

Comment thread src/cafes/Bebida.java Outdated
private int id;
private String nome;
Receitas receita;
private double preco;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

legal usar a classe BigDecimal do Java para valores que precisam de precisão decimal, como monetários

Comment thread src/cafes/Bebida.java Outdated
private String nome;
Receitas receita;
private double preco;
private static ArrayList<Bebida> menu = new ArrayList<Bebida>();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pq a bebida tem um Menu? Consegue pensar em outra classe que representaria melhor essa relação tem um menu?

Comment thread src/cafes/MaquinaDeCafe.java Outdated
public static void main(String[] args) {
Scanner cafeScanner = new Scanner(System.in);
Bebida BebidasMenu = new Bebida();
ReservatorioDeAgua reservaDeAguaAtual = new ReservatorioDeAgua();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O reservatório de água não é uma propriedade (atributo) da MaquinaDeCafe?

Comment thread src/cafes/MaquinaDeCafe.java Outdated

private static void Inicializacao(Scanner cafeScanner, int AtualQuantidadeDeAgua, Bebida BebidasMenu) {

String msgReservatorioDeAgua = AtualQuantidadeDeAgua > 50? "suficiente para " + (AtualQuantidadeDeAgua /50) + " bebidas" : "vazios, favor repor";
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

( AtualQuantidadeDeAgua > 50 ) essa condição se repete no código, poderia extrair para uma variável, assim se o reservatório de água mudar de tamanho, você só precisará alterar em um lugar

Comment thread src/cafes/MaquinaDeCafe.java Outdated

if(AtualQuantidadeDeAgua > 50){
for (int i = 0; i < BebidasMenu.getMenu().size(); i++) {
System.out.println(BebidasMenu.getMenu().get(i).getId() + " " + BebidasMenu.getMenu().get(i).getNome() + ", preço: " + (BebidasMenu.getMenu().get(i).getPreco() == 0? "grátis" : moedaEmReais(BebidasMenu.getMenu().get(i).getPreco())));
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Como vc acessa BebidasMenu.getMenu().get(i) várias vezes, poderia extrair para uma variável

Comment thread src/cafes/MaquinaDeCafe.java Outdated

private static String moedaEmReais(double valor) {
BigDecimal b = new BigDecimal(valor);
return "R$ " + b.setScale(2, RoundingMode.HALF_EVEN);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment thread src/cafes/Receitas.java Outdated
@@ -0,0 +1,51 @@
package cafes;

public class Receitas {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A classe deve representar uma unidade de negócio

@lilianjaf lilianjaf changed the title Desafio em andamento Desafio finalizado Sep 15, 2021
Copy link
Copy Markdown
Collaborator

@gcestaro gcestaro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Boa! 👏

Comment thread src/cafes/Acucar.java Outdated
}

public static ArrayList<Acucar> getNiveisDeAcucar(){
ArrayList<Acucar> Niveis = new ArrayList<Acucar>();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aqui vc tbm pode usar a interface List como retorno, assim se amanhã vc precisar mudar a implementação de ArrayList para outro tipo de List, só precisará mudar em um lugar

Comment thread src/cafes/Bebida.java Outdated
private int id;
private String nome;
Receitas receita;
Receita receita;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment thread src/cafes/MaquinaDeCafe.java Outdated

}

private static void Inicializacao(Scanner cafeScanner, ReservatorioDeAgua reservaDeAguaAtual, Bebida BebidasMenu){
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A convenção para nomear métodos e seus parâmetros é camelCase

Comment thread src/cafes/MaquinaDeCafe.java Outdated
}

private static void Inicializacao(Scanner cafeScanner, ReservatorioDeAgua reservaDeAguaAtual, Bebida BebidasMenu){
String msgReservatorioDeAgua = reservaDeAguaAtual.getQuantidadeDeAguaNoReservatorio() >= 50? "suficiente para " + (reservaDeAguaAtual.getQuantidadeDeAguaNoReservatorio() /50) + " bebidas." : "vazios.";
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quando a linha fica muito grande é legal quebrar, nesse caso poderia quebrar antes do "?" e do ":", por exemplo

Comment thread src/cafes/MaquinaDeCafe.java Outdated

System.out.println("-----Seja bem-vindo a máquina de café 2021!-----");
System.out.println("Atenção: essa máquina não devolve troco.");
System.out.println("Para sair, digite 'sair' a qualquer momento.");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a qualquer momento mesmo?

Comment thread src/cafes/MaquinaDeCafe.java Outdated

if(precoBebidaEscolhida == 0){
System.out.println("A bebida será de graça.");
BebidasMenu.getMenu().get(Integer.parseInt(bebidaEscolhida)).receita.Processo(Acucar.Nivel0, reservaDeAguaAtual);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Essa sentença BebidasMenu.getMenu().get(Integer.parseInt(bebidaEscolhida)) se repete bastante, é legal extrair para uma variável/constante

Comment thread src/cafes/MaquinaDeCafe.java Outdated
metodoDePagamentoEscolhido = getScanner(cafeScanner, "Digite 1 para pagamento em dinheiro e 2 para pagamento em cartão de débito.");
} while(metodoDePagamento(metodoDePagamentoEscolhido) == -1);

if(String.valueOf(metodoDePagamentoEscolhido).equals("1")){
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. A variável metodoDePagamentoEscolhido já é uma String, pq precisou do String.valueOf?
  2. Quando vc está comparando uma variável do código com uma constante, nesse caso "1", inverte a condição para "1".equals(metodoDePagamentoEscolhido), dessa forma nunca acontecerá um NullPointerException.
  3. "1" representa o que? Isso é conhecido como número mágico, pois não dá pra saber o que é só de olhar aqui. Uma ideia é extrair para uma constante, outra é ter um Enum de métodos de pagamento e usá-lo aqui

Comment thread src/cafes/MaquinaDeCafe.java Outdated
String sugestaoMoeda = "";
do {
sugestaoMoeda = getScanner(cafeScanner, "Digite 1 ou 2 para aceitar a sugestão ou 3 para adicionar qualquer nota ou moeda. Atenção: essa máquina não devolve troco.");
} while(aceitarSugestaoMoeda(sugestaoMoeda) == -1);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O nome do método aceitarSugestaoMoeda sugere que ele retorna um boolean, aceita ou não aceita (true/false)

Comment thread src/cafes/MaquinaDeCafe.java Outdated

System.out.println("--Favor escolher um nível de açúcar para sua bebida--");

for (int i = 0; i < Acucar.getNiveisDeAcucar().size() ; i++) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment thread src/cafes/MaquinaDeCafe.java Outdated
return SugestaoDeNotasEMoedas;
}

private static NotasEMoedas CalcularSugestoes(double Preco, NotasEMoedas NotasEMoedasReais, boolean SegundaSugestao){
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

camelCase

@lilianjaf lilianjaf changed the title Desafio finalizado Desafio atualizado Nov 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants