Unresolved compilation problems: The method is undefined for the type

1

I get the following error when compiling in Eclipse:

Exception in thread "main" java.lang.Error:
 Unresolved compilation problems: 

 The method getValor() is undefined for the type Ejercicio6
 The method mostrarProductoyValor() is undefined for the type Ejercicio6

     at Ejercicio6.main(Ejercicio6.java:55)

But I do not understand why it is. This is the code:

public class productos {

    private String producto;
    private double valor;

    public productos(String p,double v){
        this.producto=p;
        this.valor=v;

    }

    public String getProducto () { 
       return producto;  
    }

    public Double getValor () {
        return valor; 
    }

    public void mostrarProductoyValor() {
        System.out.println ("Nombre del producto: " + getProducto()+" valor: " +  getValor() );
    }


}
import java.util.Scanner;

public class Ejercicio6 extends productos {

    public Ejercicio6(String producto, double valor){
        super(producto,valor);
    }

    public static void main(String args[]){
        Ejercicio6 venta1;
        double suma,v;
        String p;
        suma=0;
        ////si fin esta en cero las ventas siguen hasta que cambie a 1
        int fin=0,i;
        i=0;
        Scanner lector=new Scanner(System.in);
        while(fin==0){
            System.out.println("Ingrese el nombre del producto "+(i+1)+":");
            p=lector.next();

            System.out.println("Ingrese el valor del producto "+(i+1)+":");
            v=lector.nextDouble();


            venta1=new Ejercicio6(p,v);
            suma=suma+venta1.getValor();

            venta1.mostrarProductoyValor();

            System.out.println("0 para siguiente venta");
            System.out.println("1 para terminar el dia");


            fin=lector.nextInt();
            i++;
        }
        System.out.println("La utilidad final es de: "+suma);


    }
}
    
asked by Alfonzo Vallejo Romero 22.04.2017 в 03:00
source

3 answers

1

Copy the code to Netbeans and compile me correctly. Possibly eclipse gave you an error. Sometimes, when I work with several projects and open files (I really keep many files and windows open), I compile many times and it stops working netbeans. It just does not compile or throw me very strange mistakes. Vast with restart and it seems that everything works fine.

Try it, your code works.

    
answered by 22.04.2017 в 04:38
0

The methods of the product class should be as follows:

protected String getProducto () { 
       return producto;  
    }
protected Double getValor () {
    return valor; 
}

protected void mostrarProductoyValor() {
    System.out.println ("Nombre del producto: " + getProducto()+" valor: " +  getValor() );
}

The protected must be used with the methods that you are going to inherit.

    
answered by 22.04.2017 в 03:52
-1
  

The method getValue () is undefined for the type Exercise6

The getValor() method does not exist in the class Ejercicio6 , I see that you do this and it is correct since Ejercicio6 extends the class productos :

 Ejercicio6 venta1;
 ...
        venta1=new Ejercicio6(p,v);
        suma=suma+venta1.getValor();

The problem must be that the package or import to the product class is incorrect.

    
answered by 22.04.2017 в 04:22