Pass the object as an argument

1

There is the + method in the Client class that calculates the discount and the points of the client, and at the end of the method, a Buying object should be instantiated, but I can not instantiate the purchase object.

Attributes and Builder of the "Buy" class:

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

Client class method:

public Compra fazUmaCompra(double p){   
    double pf = 0;
    double ds = 0;
        if (p > 300){
            if (pontos > 2000){
                pf = p - (p * 0.05);
                ds = pf - p;
                pontos = 0;
            }    
            else if (pontos > 1000){
                 pf = p - (p * 0.03);
                 ds = pf - p;
                 pontos = pontos - (int) p * 1;
            }    
            else if (pontos > 500){
                pf = p - (p * 0.02);
                ds = pf - p;
                pontos = pontos - (int) p * 1;
            }
            else
                pf = p;

    }
    pontos = pontos + (int) p * 1;
    Compra c = new Compra(p, ds, pf, this.Cliente);
    return c;

When compiling, BlueJ marks "this.Customer" as an error. "Can not find symbol - variable Client. Thanks

    
asked by anonymous 16.04.2014 / 20:14

2 answers

4

this refers to esse objeto , as you are inside a method of the Client class you should pass only the this as argument, so that you will be passing the current object, which is Client type, like parameter to the Compra counter. Please correct this:

Compra c = new Compra(p, ds, pf, this);
    
16.04.2014 / 20:18
-3

Attention to the message, friend, "Can not find symbol - client variable". Java is case sensitive, so the variable created cliente can not be called Cliente . Another thing: in your constructor, when passing values to member variables you should use this.cliente , for example, because of the scope of the variables. Using only cliente = ... you are trying to use a variable not created at this scope, that is, inside the constructor.

    
16.04.2014 / 22:23