← Unit 3 · all exercises
Saved in this browser only

Starting from empty

Write a Basket class with a no-argument constructor that starts the item count at zero. add increases the count by one, and size returns it.

class Basket { Basket(); void add(); int size(); }

Basket.java
Loading editor…
Results

Examples

  • new Basket().size() → 0
  • Basket b = new Basket(); b.add(); b.size() → 1

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