225,518 views
9 votes
9 votes
Create a public class Dog that stores a single double age set by the constructor. (Reject negative ages using assert.) Dog should also provide a single class method named isOlder. isOrder should accept two Dog instances and return true if the first is older than the second, and false otherwise. You should also assert that both passed instances are not null.

User AdamAL
by
2.7k points

1 Answer

15 votes
15 votes

Answer:

Step-by-step explanation:

The following is written in Java and has the methods as requested in the question...

class Dog {

private double age;

public Dog(double v) {

assert v >= 0:" Not valid";

this.age = v;

}

public boolean isOlder(Dog dog1, Dog dog2) {

if (dog1.age > dog2.age) {

return true;

} else {

return false;

}

}

}

User Kamalesh Wankhede
by
3.2k points