The solutions can typically be found in the solutions folder of the repository, in particular:

The solution will be published after the exercises deadline.

Study the solutions, even if your solution is okay too. Ask (or discuss with a fellow student) if you do not understand the choices made or concepts used. Typically the solutions are quite like performance assessment tasks.

week 01

Kaos at HQ The solution here is to add a test to make sure that pushing multiple elements to the stack returns them in reverse order, because that is what stacks do.
Once you have your tests ready, using it to develop your own stack cannot be that hard.
We have shown it in class (in 9 minutes, test driven!) and there is a youtube film on it with even more explanation.

Fraction exercise. We have two solutions.

  • One developed in class, which is under lessondemos as tddfraction.
    This would the modern variant with two test classes, one using parameterized tests, a JUnit 4 feature described in the test book. Note that this fraction class has less features, but it demonstrates clearly how easy setting up test can be (once you known your tools).

  • The other , the solution of a JAVA1 (yes Java 1) performace assessment some years back, which uses simple asserts (e.g. assertTrue, assertEquals), can be found in the solutions folder as fraction. This fraction is quite complete, feature wise. It has getters for numerator and denominator, more constructors, static factory methods for shorter client code and a more fancy toString()`.

week 02

In the pub exercise

There is a quite elaborate solution by Pia Erbrath in the repository, which can give you some ideas.
Note parts of such solution might reappear in an exam, but we do not expect you come up with all these fancy details in week 2 of this course. But it does provide insight where we are heading, if you follow along. You may also see some concepts of coming weeks used. That is okay and also gives a clue on where we are heading.

Answers to the questions

  • Exceptions 1

e has static type Object and you cannot throw objects (unless you cast them to Throwable, implying that the instance is a Throwable).

  • Exceptions 2

The catch statement misses the Throwable declaration. The compiler complains with error: <identifier> expected although a more appropriate message would have been Type declaration missing. This is a example how compilers work, it assumes that the first token after a parenthesis is the type token and assumes the e fulfils that role.