← Unit 3 · all exercises
Saved in this browser only

A pet

Write a Pet with a name and an age. birthday adds a year. isPuppy returns true while the age is under 1. describe returns text like "Rex is 3".

class Pet { Pet(String name, int age); void birthday(); boolean isPuppy(); String describe(); }

Pet.java
Loading editor…
Results

Examples

  • new Pet("Rex", 3).describe() → Rex is 3
  • Pet p = new Pet("Rex", 3); p.birthday(); p.describe() → Rex is 4

There are also 3 hidden tests you can't see. Solve the problem, not the examples.