-1
I have to do an exercise for the college related to sales and in the customer class I need to apply a +fazUmaCompra method.
Detail, I performed so far only part "a", I put everything in case help in solving the problem.
code in the Customer class:
public void fazUmaCompra(Compra preco){
if (preco > 300){
if (pontos > 2000){
preco = preco - (preco * 0.05);
pontos = 0;
}
else if (pontos > 1000){
preco = preco - (preco * 0.03);
pontos = pontos -preco / 1;
}
else if (pontos > 500){
preco = preco - (preco * 0.02);
pontos = pontos -preco / 1;
}
else
preco = preco;
}
}
EDIT: CLASS PURCHASE
public class Compra{
private String numero;
private Cliente cliente;
private Vendedor vendedor;
private double precoOriginal;
private double desconto;
private double preco;
public Compra(double pO, double ds, double pF, Cliente client){
cliente = client;
String s = cliente.getNome();
String sub = s.substring(0, 3);
String num = String.valueOf((int)(Math.random()*10000+100));
numero = num + sub;
precoOriginal = pO;
desconto = ds;
preco = pF;
}
public Compra(double prO, double dst, double prF, Cliente client, Vendedor vend){
cliente = client;
String s = cliente.getNome();
String sub = s.substring(0, 3);
String num = String.valueOf((int)(Math.random()*10000+100));
numero = num + sub;
precoOriginal = prO;
desconto = dst;
preco = prF;
vendedor = vend;
}
public void impoeDesconto(double desct){
}
public void setVendedor(Vendedor vend){
vendedor = vend;
}
public void emiteNotaFiscal(){
System.out.println("Número da Compra: " + numero);
System.out.println("Nome do Cliente: " + this.cliente.getNome());
if (vendedor = null)
vendedor = vendedor;
else
System.out.println("Nome do Vendedor: " + this.vendedor.getNome());
System.out.println("Preço Inicial: " + precoOriginal);
System.out.println("Valor do desconto: " + desconto);
System.out.println("Preço Pago: " + preco);
}
public double getPreco(){
return preco;
}
}
EDIT: CLIENT CLASS
private String nome;
private Endereco endereco;
private int pontos;
public Cliente(String nm, Endereco ed){
nome = nm;
endereco = ed;
pontos = 0;
}
public Cliente(String nm){
this.nome = nm;
this.endereco = new Endereco();
}
// alteraEndereco funcionamento errado
public void alteraEndereco(){
this.endereco.altera();
}
public void fazUmaCompra(Compra preco){
if (preco.getPreco() > 300){
if (pontos > 2000){
preco.getPreco() = preco.getPreco() - (preco.getPreco() * 0.05);
pontos = 0;
}
else if (pontos > 1000){
preco.getPreco() = preco.getPreco() - (preco.getPreco() * 0.03);
pontos = pontos -preco / 1;
}
else if (pontos > 500){
preco.getPreco() = preco.getPreco() - (preco.getPreco() * 0.02);
pontos = pontos -preco / 1;
}
else
preco = preco;
}
}
public String getNome(){
return nome;
}
}
The occore error on the line:
if (preco > 300){
bad operand types for Binary Operator '>'
Where
Bad Operand types for binary operator
gets into your doubt?– Math
sorry, I forgot to put this information in the post, I will edit.
– leonardokbruksch
Friend, what is your question? after all we will not do the exercise just help where is the problem.
– Israel Zebulon
Could put your class
Compra
for us?– Math
Buying price is a correct class, so must have price.[here the field you will know if and > 300]. Example price.getPreco() > 300, if you compare the class will give error even !!!
– user6026
Preco is an object and not a variable! should do something like preco->getValor().
– Israel Zebulon
Fulvio, how could I do that if the price attribute of the Purchase class should be private? a get method maybe?
– leonardokbruksch
@user3511983, use get/set in
private
who wishes to exhibit outside the class !!!– user6026
OK Fulvio!! thank you very much
– leonardokbruksch
points = price points / 1; missed here ó
– Math