Given the below class: public class Dog { private String name; private double weight; private static int numDogs = 0; public Dog(String name, double weight) { this.name = name; this.weight = weight; numDogs++; } public String getName() { return name; } public double getWeight() { return weight; } public static int getNumDogs() { return numDogs; } public static void increaseNumDogs() { numDogs++; } public void printGreeting() { System.out.println("Woof!"); } @Override public String toString() { return "Name: " + name + "\nWeight: " + weight; } } Add a method call to getNumDogs to the below starter code: public class DogTest { public static void main(String[] args) { Dog fluffy = new Dog("Fluffy", 10); int num = //call getNumDogs method here } } Then, add a method call to the increaseNumDogs method.
(Java)
Q 4,5
COMPLETE BOTH STEPS
Explain the answer step-by-step and include verbal explanation. Thank you!
Given the below class:
public class Dog {
private String name;
private double weight;
private static int numDogs = 0;
public Dog(String name, double weight) {
this.name = name;
this.weight = weight;
numDogs++;
}
public String getName() {
return name;
}
public double getWeight() {
return weight;
}
public static int getNumDogs() {
return numDogs;
}
public static void increaseNumDogs() {
numDogs++;
}
public void printGreeting() {
System.out.println("Woof!");
}
@Override public String toString() {
return "Name: " + name + "\nWeight: " + weight;
}
}
Add a method call to getNumDogs to the below starter code:
public class DogTest {public static void main(String[] args) {
Dog fluffy = new Dog("Fluffy", 10);
int num = //call getNumDogs method here
}
}
Then, add a method call to the increaseNumDogs method.
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 1 images