Hi, I'm doing a program on the weight of people and I have to do several methods one of them is: averageWe're in the class Statistics of People but my problem is that I do not know how to call a variable or the method getPeso () which is of the Person class to calculate it, because if I put only getPeso () I get error in eclipse and it tells me that I must create that method within the class Statistics of People but I want to call it from the Person class because as I did it there , so that I am going to create again the same one in another class ... for now it arrives until here:
public class Persona {
private String nombre ;
private int edad;
private double peso;
private String genero ;
private double altura;
public Persona(String nombre , int edad , double peso , String genero , double altura) {
this.nombre = nombre ;
this.edad = edad ;
this.peso = peso;
this.genero = genero;
this.altura = altura;
}
public String toString() {
return "EstadisticasDePersonas [nombre=" + nombre + ", edad=" + edad + ", peso=" + peso + ", genero=" + genero
+ ", altura=" + altura + "]";
}
public String getNombre () {
return this.nombre;
}
public void setNombre (String nombre) {
this.nombre = nombre;
}
public int getEdad () {
return this.edad;
}
public void setEdad(int edad) {
this.edad = edad;
}
public double getPeso() {
return this.peso ;
}
public void setPeso() {
this.peso = peso;
}
public String getGenero() {
return this.genero;
}
public void setGenero (String genero) {
this.genero = genero;
}
public double getAltura() {
return this.altura;
}
public void setAltura() {
this.altura = altura;
}
}
public class EstadisticasDePersonas {
private String nombre ;
public EstadisticasDePersonas (String nombre) {
this.nombre =nombre;
}
public double pesoPromedio() {
int contadorPeso=0;
int sumatoriaPeso =0;
double pesoPromedio=0.0;
if (getPeso()>0) {
contadorPeso++;
}
sumatoriaPeso+=contadorPeso;
pesoPromedio= sumatoriaPeso/50;
return pesoPromedio;
}