I'm a beginner learning java. I have the following question;
I want to assign the value of the static variable Dog.averageWeight to an object variable dog1.weight.
I want the dog.weight = 3;
I've tried different options, but it doesn't work. Can someone please tell me if this works and how?
public static int numberOfAllDogs;
public static int totalWeight;
public static int averageWeight;
public String name;
public int weight;
public void initialize(String name) {
this.name = name;
this.weight = weight;
numberOfAllDogs++;
}
public void initialize(String name, int weight) {
this.name = name;
this.weight = weight;
numberOfAllDogs++;
totalWeight = totalWeight + this.weight;
}
public static void main(String[] args) {
Dog dog1 = new Dog();
Dog dog2 = new Dog();
dog1.initialize("daisy");
dog2.initialize("chuck", 5);
dog2.initialize("marco", 5);
dog2.initialize("emy", 5);
averageWeight = totalWeight / numberOfAllDogs;
System.out.println("Total weight: " + totalWeight); //15
System.out.println("Avvarage weight: " + averageWeight); // 3
System.out.println(dog2.weight);
System.out.println(dog1.weight);
}
}