Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given the below class: public class Dog { private String name; private double weight; private static int numDogs = 0; public Dog(String name, double weight)

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 + " Weight: " + weight;

}

}

1. 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!

}

}

1. Dog.getNumDogs();

2. Then, add a method call to the increaseNumDogs method.

3. Lastly, call the printGreeting method. What is different about the way you call this method compared to the prior two methods.

(answer only questions 2 and 3 )

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Marketing The New Profit Frontier

Authors: Ed Burnett

1st Edition

0964535629, 978-0964535626

More Books

Students also viewed these Databases questions

Question

Tell the merits and demerits of Mendeleev's periodic table.

Answered: 1 week ago

Question

What roles have these individuals played in your life?

Answered: 1 week ago

Question

1. Write down two or three of your greatest strengths.

Answered: 1 week ago