简体   繁体   中英

Compilation error, but i can't find the cause

I'm trying to compile a code in Java to return a boolean, he's calling another two methods, but, for some odd reason, is not recognizing the method's name.

The compiler send me this error: Cannot find symbol, Method transaccionMaquina(Producto, Tarjeta)

Here is the code:

import java.util.Scanner;
public class Maquina
{
    Maquina ()
    {
    }

    public boolean transaccionMaquina(Tarjeta TjtNuevo, Producto PrdNuevo)
    {
                if (PrdNuevo.getPrecio()<= TjtNuevo.getSaldoTarjeta())
                {
                   PrdNuevo.setStock(PrdNuevo.getStock()-1);
                   TjtNuevo.setSaldoTarjeta(TjtNuevo.getSaldoTarjeta()-PrdNuevo.getPrecio());
                   return true;
                }
                else
                {
                    return false;
                }
     } 
}

Any question, suggestion or constructive criticism, would be much appreciated

Here is the code of the class who possess the method i'm calling

Here is the place inside menu class where i'm trying to add it

 // MÉTODOS (Ver Después)

public boolean ventaEfectivo(Producto PrdNuevo, Cliente ClntNuevo)
{
    int intPrecio = PrdNuevo.getPrecio();
    int intDineroDisponible = ClntNuevo.getDineroDisponible();
    int intStock = PrdNuevo.getStock();
        if (intDineroDisponible>=intPrecio)
        {
            intDineroDisponible = intDineroDisponible - intPrecio;
            ClntNuevo.setDineroDisponible(intDineroDisponible);
            intStock = intStock - 1;
            PrdNuevo.setStock(intStock); 
            return true;
        }
        else
        {
            return false;
        }
}

public boolean pagoProducto(Producto PrdNuevo, Cliente ClntNuevo, Tarjeta TjtNuevo, int intOpcion)
        {
            switch(intOpcion) {
                case 1:

                    return ventaEfectivo(PrdNuevo, ClntNuevo);

                break;

                case 2:

                    return transaccionMaquina(PrdNuevo, TjtNuevo);
                break;

                default:
            }   
        }

Thanks in advance.

Your arguments are defined in the original method this way:

public boolean transaccionMaquina(Tarjeta TjtNuevo, Producto PrdNuevo)

You're calling it this way:

return transaccionMaquina(PrdNuevo, TjtNuevo);

In short, the arguments are reversed.

You've interchanged the parameters when calling your method, which therefore does not match the method signature:

public boolean transaccionMaquina(Tarjeta TjtNuevo, Producto PrdNuevo) { ... }

public boolean pagoProducto(Producto PrdNuevo, Cliente ClntNuevo, Tarjeta TjtNuevo, int intOpcion){
    ...
    case 2:  return transaccionMaquina(PrdNuevo, TjtNuevo);
    ....
}

Your snippets is not very clear to me. Based on my interpretation, the code which calls transaccionMaquina() is in another class and probably these classes are not in hierarchy. You need to create an object of Maquina class. and then call transaccionMaquina using it.

Maquina m = new Maquina();
m.transaccionMaquina()

You probably should read on object oriented programming to clear your concepts

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM