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