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.

1. 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 lesson demos 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 PRC1 (yes Java 1) performance 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()`.

2. 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 to fulfil that role.

3. week 03

3.1. Olifantys

Week 3’s olifantys exercise may cause confusion, because there is not one good solution, for the functionality anyway. It is all about getting the relations in the class diagram properly implemented. Functionality you could implement is throwing a party, because it is fun, inviting teachers and students alike. You could eg. inspired by our solution on Olifantys solution in the exercise repository.

The bottom line is: use your fantasy (hint is in the name of the project).

3.2. Shape filter

The shape filter exercise is on PECS (Producer Extends, Consumer Super). solution is in the repo under shape filter solution

3.3. drinkers

The exercise is a combination of understanding a class diagram and how to use 'consumers' type safely. Again: PECS. drinkers solution

4. week 04

4.1. Using lambda to implement comparables.

Here you can see that using lambda to implement a comparable is really easy. You will not want it any other way from now on. solution

4.2. Two stacks

Using the same test for two implementations is what this exercise is about. You refactor both the tests and the implementation (by extracting the appropriate interface).

4.3. Lambda calc.

Combine enum and lambdas. lambda calc solution

5. week 05

Lambdas and streams.

5.1. csv object stream

Best is to start with csvobjectstream, because that can be used in the next project (and might be in the exam). Note how a lambda can be used to express the filter.

5.2. Lambda Library

Our solution includes a JavaFX Gui. You may use it as an example for binding.

6. week 06

6.1. Simple Rest Like Protocol

We again use an enum in the implementation, in particular one enum instance for each command type.

7. week 07

7.1. Simple Rest Like Protocol with database

The same as last week, now with a backing database.

Study it to see how we stick to the Do not Repeat Yourselves by avoiding code duplication as much as possible.

8. week 08

8.1. Rest testing workshop

After trying your hand with the rest-assured workshop, you should quickly get up and running with this technology, because, when you have it in your fingers, it will help you write rest test very quickly. Concentrate on the rest-assured framework.

Our solution is online .

8.2. easy rest crud with postgres tricks.

For the restful president service, stay tuned.