Skip to content

PR - Matheus - Pratica de Lambda#1

Open
FriedrichMatheus wants to merge 1 commit intoDeividFrancis:mainfrom
FriedrichMatheus:main
Open

PR - Matheus - Pratica de Lambda#1
FriedrichMatheus wants to merge 1 commit intoDeividFrancis:mainfrom
FriedrichMatheus:main

Conversation

@FriedrichMatheus
Copy link
Copy Markdown

@FriedrichMatheus FriedrichMatheus commented Oct 3, 2022

Minha tentativa de realizar os desafios propostos.

Copy link
Copy Markdown

@deividdotum deividdotum left a 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() {
Copy link
Copy Markdown

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>();
Copy link
Copy Markdown

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 {
Copy link
Copy Markdown

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.

Copy link
Copy Markdown
Author

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) {
Copy link
Copy Markdown

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.

Copy link
Copy Markdown
Author

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() {
Copy link
Copy Markdown

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.

Copy link
Copy Markdown
Author

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

image

revisei o codigo e eu ja tinha feito o metodo

BigDecimal carrinhoList = Main.carrinhoList.stream()
.filter(c -> c.getCategoria() == Categoria.Esporte)
.map(Carrinho::getValor)
.reduce(new BigDecimal(0),(a, n) -> a.add(n));
Copy link
Copy Markdown

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);

Copy link
Copy Markdown
Author

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)
Copy link
Copy Markdown

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)
Copy link
Copy Markdown

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)
Copy link
Copy Markdown

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)
Copy link
Copy Markdown

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.

@DeividFrancis DeividFrancis self-requested a review October 3, 2022 14:53
@FriedrichMatheus
Copy link
Copy Markdown
Author

Irei corrigir os pontos citados acima, obrigado pelo tempo 🐸

@FriedrichMatheus FriedrichMatheus changed the title Toma pae PR - Matheus - Pratica de Lambda Oct 4, 2022
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