-
Notifications
You must be signed in to change notification settings - Fork 10
PR - Matheus - Pratica de Lambda #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parabéns por se comprometer a desenvolver as atividades, em uma analise geral o código está bem satisfatório, adicionei umas dicas para evoluir seu código junto com uns pontos para refazer a atividade espero que resolva as atividades restantes.
// getHighestPrice(); | ||
} | ||
|
||
public static void getTecnologia() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ainda é para retorna a lista de Produtos não somente o nome.
Revise as perguntas e os métodos para identificar onde esta pedido o retorno da lista de produtos ou somente um atributo do objeto.
|
||
public class Main { | ||
|
||
private static List<Carrinho> carrinhoList = new ArrayList<Carrinho>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
O intuito era criar uma casse Produto
mas faz sentido também ser Carrinho
.
|
||
public class Carrinho { | ||
|
||
public enum Categoria { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Achei legal ter criado um enum
para categorias, mas o padrão java para enums
sempre é em maiúsculas.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Obrigado.
carrinhoList.add(new Carrinho(573, "Tapete Geometrico", new BigDecimal(114.00), Boolean.TRUE, Categoria.Lazer)); | ||
} | ||
|
||
public static void main(String[] args) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Não consigo vincular de forma simples qual método é a resposta de cada pergunta, fica como dica adicionar um comentário com a questão para ajudar quem vai corrigir kkk.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Realmente ficou bem confuso
System.out.println(carrinhoList); | ||
} | ||
|
||
public static void getValorMaior() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Falta identifica somente os produtos com estoque como verdadeiro.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A, pulei esse da lista sem querer kkkkk
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BigDecimal carrinhoList = Main.carrinhoList.stream() | ||
.filter(c -> c.getCategoria() == Categoria.Esporte) | ||
.map(Carrinho::getValor) | ||
.reduce(new BigDecimal(0),(a, n) -> a.add(n)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DICA: Uma alternativa para essa linha seria: (ps: nao executei para ver se tem algum detalhe na implentação)
.reduce(BigDecimal.ZERO,BigDecimal::add);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implementei e deu tudo certo!
|
||
public static void getSumEsport() { | ||
BigDecimal carrinhoList = Main.carrinhoList.stream() | ||
.filter(c -> c.getCategoria() == Categoria.Esporte) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DICA: Alternativa de código: (Assim evita que estoura NullPointerException
caso o c.getCategoria()
vem null
)
.filter(c -> Categoria.Esporte.equals(c.getCategoria))
|
||
public static void getEquipamento() { | ||
String carrinhoList = Main.carrinhoList.stream() | ||
.filter(c -> c.categoria == Categoria.Equipamentos) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Não é muito aceita essa forma de acessar o atributo c.categoria
, poderia utilizar como no método acima:
.filter(c -> Categoria.Esporte.equals(c.getCategoria))
public static void getEquipamento() { | ||
String carrinhoList = Main.carrinhoList.stream() | ||
.filter(c -> c.categoria == Categoria.Equipamentos) | ||
.map(Carrinho::getNome) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Não deveria pegar somente os nomes mas sim o Objeto inteiro
|
||
public static void getOrderList() { | ||
List<String> carrinhoList = Main.carrinhoList.stream() | ||
.map(Carrinho::getNome) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Não deveria pegar somente os nomes mas sim o Objeto inteiro.
Irei corrigir os pontos citados acima, obrigado pelo tempo 🐸 |
Minha tentativa de realizar os desafios propostos.