Skip to content
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

Desafio QA - Gercélia Ramos #82

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
29 changes: 29 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src.main.java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/target/
/bin/
23 changes: 23 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>qa-recruiting-brazil</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
11 changes: 11 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.5
4 changes: 4 additions & 0 deletions .settings/org.eclipse.m2e.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
Binary file added ESPECIFICAÇÃO DO WHATSAPP - BDD.pdf
Binary file not shown.
40 changes: 40 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>qa-recruiting-brazil-g</groupId>
<artifactId>qa-recruiting-brazil-g</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.6.2</version>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.16.1</version>
</dependency>

</dependencies>



</project>
85 changes: 85 additions & 0 deletions src.main.java/com/concrete/desafio/Checkout.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package com.concrete.desafio;

import java.util.*;

public class Checkout {



public static TreeMap<String, Integer> listaDeItens = new TreeMap<String, Integer>();

public void adicionarItem(String item, Integer qtd) {

if (!listaDeItens.containsKey(item))
listaDeItens.put(item, qtd);
else {
listaDeItens.put(item, qtd + listaDeItens.get(item));
}
}

public static void removeItem(String item, Integer quantity) throws Exception {

if (!listaDeItens.containsKey(item))
throw new Exception("Esse item não existe no seu carrinho");

if (listaDeItens.get(item) == quantity)
listaDeItens.remove(item);
else if (listaDeItens.get(item) > quantity)
listaDeItens.put(item, listaDeItens.get(item) - quantity);
else
throw new Exception("Quantidade para o item fornecido é maior do que a quantidade no carrinho");
}

public static void revisarCarrinho() throws Exception {


Set<String> todosItensdoCarrinho = listaDeItens.keySet();
for (Iterator<String> i = todosItensdoCarrinho.iterator(); i.hasNext();) {
String item = i.next();
Integer qtdd = listaDeItens.get(item);
System.out.println("Item: " + item + " quantidade: " + qtdd);
}
}

public static void limparCarrinho() {
listaDeItens.clear();
}

//static
public double calcularPrecoTotal(TreeMap<String, Integer> listaDeItens) {
Double total = 0.0;

Set<String> keys = listaDeItens.keySet();
for (Iterator<String> i = keys.iterator(); i.hasNext();) {
String item = i.next();
Integer quantidade = listaDeItens.get(item);

if (ProdutoEmOferta.produtoOferta.containsKey(item)) {

Produto produto = ProdutoEmOferta.produtoOferta.get(item);

if (produto.qtd < quantidade) {
total += (quantidade % produto.qtd) * PrecoDosProdutos.precoProduto.get(item)
+ (quantidade / produto.qtd) * produto.preco;
} else if (produto.qtd == quantidade) {
total += produto.preco;
} else {
total += (quantidade) * PrecoDosProdutos.precoProduto.get(item);
}
} else {
total += (quantidade) * PrecoDosProdutos.precoProduto.get(item);
}
}

return total;
}

public static TreeMap<String, Integer> getListaDeItens() {
return listaDeItens;
}

public static void setListaDeItens(TreeMap<String, Integer> listaDeItens) {
Checkout.listaDeItens = listaDeItens;
}

}
16 changes: 16 additions & 0 deletions src.main.java/com/concrete/desafio/PrecoDosProdutos.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.concrete.desafio;

import java.util.*;

public class PrecoDosProdutos {

public static TreeMap<String, Double> precoProduto = new TreeMap<String, Double>();

static{
precoProduto.put("A", 50.0);
precoProduto.put("B", 30.0);
precoProduto.put("C", 20.0);
precoProduto.put("D", 15.0);
}

}
13 changes: 13 additions & 0 deletions src.main.java/com/concrete/desafio/Produto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.concrete.desafio;

public class Produto {
public String nome;
public Integer qtd;
public Double preco;

public Produto (String Nome, Integer Quantidade, Double Preco){
nome = Nome;
qtd = Quantidade;
preco = Preco;
}
}
15 changes: 15 additions & 0 deletions src.main.java/com/concrete/desafio/ProdutoEmOferta.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.concrete.desafio;

import java.util.*;

public class ProdutoEmOferta {

public static TreeMap<String, Produto> produtoOferta = new TreeMap<String, Produto>();


static{
produtoOferta.put("A", new Produto("A", 3, 130.0));
produtoOferta.put("B", new Produto("B", 2, 45.0));
}

}
107 changes: 107 additions & 0 deletions src.main.java/com/concrete/desafio/app/App.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package com.concrete.desafio.app;

import com.concrete.desafio.Checkout;

public class App {

public static void main(String[] args) {

Checkout carrinho = new Checkout();

try {
Checkout.revisarCarrinho();
} catch (Exception e) {
System.out.println(e.toString());
}

// A - 50 reais - promocao 3 = 130
System.out.println("");
carrinho.adicionarItem("A", 3);
try {
Checkout.revisarCarrinho();
} catch (Exception e) {

System.out.println(e.toString());
}

Double carrinho1 = carrinho.calcularPrecoTotal(Checkout.listaDeItens);
System.out.println("Preço total 1: " + carrinho1);
System.out.println("");



// B - 30 reais - promocao 2 = 45
carrinho.adicionarItem("B", 2);
try {
Checkout.revisarCarrinho();
} catch (Exception e) {

System.out.println(e.toString());
}
Double carrinho2 = carrinho.calcularPrecoTotal(Checkout.listaDeItens);
System.out.println("Preço total 2: " + carrinho2);
System.out.println("");

carrinho.adicionarItem("C", 4);
try {
Checkout.revisarCarrinho();
;
} catch (Exception e) {
System.out.println(e.toString());
}
Double carrinho3 = carrinho.calcularPrecoTotal(Checkout.listaDeItens);
System.out.println("Preço total 3: " + carrinho3);
System.out.println("");
try {
Checkout.removeItem("B", 2);
} catch (Exception e1) {
System.out.println(e1.toString());
}
try {
Checkout.revisarCarrinho();
;
} catch (Exception e) {
System.out.println(e.toString());
}
Double carrinho4 = carrinho.calcularPrecoTotal(Checkout.listaDeItens);
System.out.println("Preço total 4: " + carrinho4);
System.out.println("");
try {
Checkout.removeItem("A", 1);
} catch (Exception e1) {
System.out.println(e1.toString());
}
try {
Checkout.revisarCarrinho();
} catch (Exception e) {
System.out.println(e.toString());
}
Double carrinho5 = carrinho.calcularPrecoTotal(Checkout.listaDeItens);
System.out.println("Preço total 5: " + carrinho5);
System.out.println("");

try {
Checkout.revisarCarrinho();
} catch (Exception e) {
System.out.println(e.toString());
}
Double carrinho6 = carrinho.calcularPrecoTotal(Checkout.listaDeItens);
System.out.println("Preço total 6: " + carrinho6);
System.out.println("");

carrinho.adicionarItem("A", 4);

try {
Checkout.revisarCarrinho();
} catch (Exception e) {
System.out.println(e.toString());
}
Double carrinho7 = carrinho.calcularPrecoTotal(Checkout.listaDeItens);
System.out.println("Preço total 7: " + carrinho7);

//JOptionPane.showMessageDialog(null,"Preço total 1: " + carrinho1 + "\n" +
//"Preço total 2: " + carrinho2 + "\n");


}
}