Created
May 16, 2017 18:41
-
-
Save Rafael11j/c6c82b08093b76227de09619a816f22a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package atividade; | |
public class Produto { | |
private String codigo; | |
private String descricao; | |
private double valorVenda; | |
private double valorCusto; | |
private boolean promocao; | |
public Produto(String codigo, String descricao, double valorVenda, double valorCusto, boolean promocao) { | |
super(); | |
this.codigo = codigo; | |
this.descricao = descricao; | |
this.valorVenda = valorVenda; | |
this.valorCusto = valorCusto; | |
this.promocao = promocao; | |
} | |
public String getCodigo() { | |
return codigo; | |
} | |
public void setCodigo(String codigo) { | |
this.codigo = codigo; | |
} | |
public String getDescricao() { | |
return descricao; | |
} | |
public void setDescricao(String descricao) { | |
this.descricao = descricao; | |
} | |
public double getValorVenda() { | |
return valorVenda; | |
} | |
public void setValorVenda(double valorVenda) { | |
this.valorVenda = valorVenda; | |
} | |
public double getValorCusto() { | |
return valorCusto; | |
} | |
public void setValorCusto(double valorCusto) { | |
this.valorCusto = valorCusto; | |
} | |
public boolean isPromocao() { | |
return promocao; | |
} | |
public void setPromocao(boolean promocao) { | |
this.promocao = promocao; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package atividade; | |
import java.util.Scanner; | |
public class Venda { | |
private Produto produto; | |
private Vendedor vendedor; | |
private double desconto; | |
private int qtdItens; | |
private double valor; | |
private Scanner leitor; | |
public void cacularValor(){ | |
leitor = new Scanner(System.in); | |
try{ | |
System.out.println("Digite o valor da venda: "); | |
double vaVenda = leitor.nextDouble(); | |
System.out.println("Digite a quantidade de itens: "); | |
qtdItens = leitor.nextInt(); | |
System.out.println("Tem desconto? (1 - sim) (2 - não)"); | |
int op = leitor.nextInt(); | |
if(op == 1){ | |
valor = vaVenda * qtdItens; | |
valor = valor - desconto; | |
}else{ | |
valor = vaVenda * qtdItens; | |
} | |
System.out.println(valor); | |
}catch (NullPointerException e) { | |
} | |
} | |
public void calcularComissao(){ | |
double comissao; | |
try{ | |
comissao = (vendedor.comissao * produto.getValorVenda()); | |
if(produto.isPromocao()){ | |
comissao = comissao/2; | |
} | |
}catch (Exception e) { | |
} | |
} | |
public void efetuarDesconto(double pDesconto){ | |
try{ | |
pDesconto = produto.getValorVenda() - desconto; | |
valor = produto.getValorVenda() - pDesconto; | |
if(valor < produto.getValorCusto() ){ | |
System.out.println("O desconto não pode ser realizado!"); | |
}else{ | |
System.out.println("Desconto realizado!"); | |
} | |
}catch (Exception e) { | |
} | |
} | |
public void imprimir(){ | |
try{ | |
System.out.println("Codigo: "+ vendedor.getCodigo() + " Nome: " + vendedor.getNome() + " Comissão: " + vendedor.comissao); | |
System.out.println("Número de itens vendidos: " + qtdItens); | |
System.out.println("Código do produto: " + produto.getCodigo() + " Descrição: " + produto.getDescricao()); | |
System.out.println("O valor da venda é: " + produto.getValorVenda()); | |
if(produto.isPromocao()){ | |
System.out.println("O produto está em promoção"); | |
}else{ | |
System.out.println("O produto não está em promoção"); | |
} | |
System.out.println("O valor do desconto é: " + desconto); | |
System.out.println("O valor total da venda é de : " + valor); | |
}catch (Exception e) { | |
} | |
} | |
public Produto getProduto() { | |
return produto; | |
} | |
public void setProduto(Produto produto) { | |
this.produto = produto; | |
} | |
public Vendedor getVendedor() { | |
return vendedor; | |
} | |
public void setVendedor(Vendedor vendedor) { | |
this.vendedor = vendedor; | |
} | |
public int getQtdItens() { | |
return qtdItens; | |
} | |
public void setQtdItens(int qtdItens) { | |
this.qtdItens = qtdItens; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package atividade; | |
public class Principal { | |
public static void main(String[] args) { | |
Produto p = new Produto("12345", "Notebook", 2500, 2000, false); | |
Vendedor v = new Vendedor("Mario", "01", "Rua tal"); | |
Venda venda = new Venda(); | |
System.out.println("A venda é referente a dois itens "); | |
venda.cacularValor(); | |
venda.imprimir(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package atividade; | |
public class Vendedor { | |
private String nome; | |
private String codigo; | |
public double comissao; | |
private String end; | |
public Vendedor(String nome, String codigo, String end) { | |
super(); | |
this.nome = nome; | |
this.codigo = codigo; | |
this.end = end; | |
} | |
public String getNome() { | |
return nome; | |
} | |
public void setNome(String nome) { | |
this.nome = nome; | |
} | |
public String getCodigo() { | |
return codigo; | |
} | |
public void setCodigo(String codigo) { | |
this.codigo = codigo; | |
} | |
public double getComissao() { | |
return comissao; | |
} | |
public void setComissao(double comissao) { | |
this.comissao = comissao; | |
} | |
public String getEnd() { | |
return end; | |
} | |
public void setEnd(String end) { | |
this.end = end; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment