PR - Matheus - Pratica de Lambda#1
PR - Matheus - Pratica de Lambda#1FriedrichMatheus wants to merge 1 commit intoDeividFrancis:mainfrom
Conversation
| // getHighestPrice(); | ||
| } | ||
|
|
||
| public static void getTecnologia() { |
There was a problem hiding this comment.
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.
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.
Achei legal ter criado um enum para categorias, mas o padrão java para enums sempre é em maiúsculas.
| 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.
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.
Realmente ficou bem confuso
| System.out.println(carrinhoList); | ||
| } | ||
|
|
||
| public static void getValorMaior() { |
There was a problem hiding this comment.
Falta identifica somente os produtos com estoque como verdadeiro.
There was a problem hiding this comment.
A, pulei esse da lista sem querer kkkkk
| 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.
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.
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.
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.
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.
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.
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.