Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 95a1753

Browse files
Collections course
1 parent a65bf08 commit 95a1753

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1658
-0
lines changed

‎carrinho-de-compras/.gitignore

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
### IntelliJ IDEA ###
2+
out/
3+
!**/src/main/**/out/
4+
!**/src/test/**/out/
5+
6+
### Eclipse ###
7+
.apt_generated
8+
.classpath
9+
.factorypath
10+
.project
11+
.settings
12+
.springBeans
13+
.sts4-cache
14+
bin/
15+
!**/src/main/**/bin/
16+
!**/src/test/**/bin/
17+
18+
### NetBeans ###
19+
/nbproject/private/
20+
/nbbuild/
21+
/dist/
22+
/nbdist/
23+
/.nb-gradle/
24+
25+
### VS Code ###
26+
.vscode/
27+
28+
### Mac OS ###
29+
.DS_Store

‎carrinho-de-compras/.idea/.gitignore

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎carrinho-de-compras/.idea/misc.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎carrinho-de-compras/.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
</component>
11+
</module>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package controller;
2+
3+
import model.Carrinho;
4+
5+
public class User {
6+
public static void main(String[] args) {
7+
Carrinho carrinho = new Carrinho();
8+
9+
//adicionando produtos
10+
carrinho.adicionarProduto("Agua mineral", 6, 1.99);
11+
carrinho.adicionarProduto("Chocolate", 2, 6.49);
12+
carrinho.adicionarProduto("Pêra", 3, 4.69);
13+
carrinho.adicionarProduto("Caixa de Uva", 2, 6.49);
14+
carrinho.adicionarProduto("Requeijão", 2, 8.99);
15+
carrinho.adicionarProduto("Queijo", 1, 12.99);
16+
17+
//exibindo os produtos
18+
System.out.println(carrinho.exibirProdutos());
19+
20+
//calculando o preço
21+
System.out.println(carrinho.calcularValorTotal());
22+
23+
//removendo produtos
24+
carrinho.removerProduto("Queijo");
25+
carrinho.removerProduto("Caixa de Uva");
26+
27+
//exibindo novamente
28+
System.out.println(carrinho.exibirProdutos());
29+
30+
//calculando novamente
31+
System.out.println(carrinho.calcularValorTotal());
32+
}
33+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package model;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
public class Carrinho {
7+
List<Produto> carrinhoCompras;
8+
9+
public Carrinho() {
10+
this.carrinhoCompras = new ArrayList<>();
11+
}
12+
13+
public void adicionarProduto(String nome, int quantidade, double preco) {
14+
this.carrinhoCompras.add(new Produto(nome, quantidade, preco));
15+
16+
}
17+
18+
public void removerProduto(String nome) {
19+
for (Produto p : this.carrinhoCompras) {
20+
if (p.getNome().equalsIgnoreCase(nome)) {
21+
this.carrinhoCompras.remove(p);
22+
break;
23+
24+
}
25+
26+
}
27+
28+
}
29+
30+
public double calcularValorTotal() {
31+
double acum = 0;
32+
33+
for (Produto p : this.carrinhoCompras) {
34+
acum += (p.getPreco() * p.getQuantidade());
35+
}
36+
37+
return acum;
38+
}
39+
40+
public String exibirProdutos() {
41+
StringBuilder exibir = new StringBuilder("Os produtos do carrinho são\n");
42+
43+
for (Produto p : this.carrinhoCompras) {
44+
exibir.append("{").append("Nome: ").append(p.getNome()).append(", Quantidade:").append(p.getQuantidade());
45+
exibir.append(", Preço:").append(p.getPreco()).append("}");
46+
47+
if (p != this.carrinhoCompras.getLast()) {
48+
exibir.append("\n");
49+
}
50+
}
51+
52+
return exibir.toString();
53+
}
54+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package model;
2+
3+
public class Produto {
4+
private String nome;
5+
private int quantidade;
6+
private double preco;
7+
8+
public Produto(String nome, int quantidade, double preco) {
9+
this.nome = nome;
10+
this.quantidade = quantidade;
11+
this.preco = preco;
12+
}
13+
14+
public String getNome() {
15+
return this.nome;
16+
}
17+
18+
public int getQuantidade() {
19+
return this.quantidade;
20+
}
21+
22+
public double getPreco() {
23+
return this.preco;
24+
}
25+
}

‎conjunto-de-palavraas-unicas/.gitignore

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
### IntelliJ IDEA ###
2+
out/
3+
!**/src/main/**/out/
4+
!**/src/test/**/out/
5+
6+
### Eclipse ###
7+
.apt_generated
8+
.classpath
9+
.factorypath
10+
.project
11+
.settings
12+
.springBeans
13+
.sts4-cache
14+
bin/
15+
!**/src/main/**/bin/
16+
!**/src/test/**/bin/
17+
18+
### NetBeans ###
19+
/nbproject/private/
20+
/nbbuild/
21+
/dist/
22+
/nbdist/
23+
/.nb-gradle/
24+
25+
### VS Code ###
26+
.vscode/
27+
28+
### Mac OS ###
29+
.DS_Store

‎conjunto-de-palavraas-unicas/.idea/.gitignore

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /