Skip to content

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

FriedrichMatheus
Copy link

@FriedrichMatheus FriedrichMatheus commented Oct 3, 2022

Minha tentativa de realizar os desafios propostos.

Copy link

@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() {

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

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 {

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

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
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() {

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

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

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)

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)

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)

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