Exercises_class_4.pdf

Exercises, class 4

1. a) Put yourself in the following situation:

• You are tasked with coding a management system for a donut store – such as Tim Hortons or Dunkin Donuts.

• You have to create two interfaces: ◦ Exchangeable, with two methods:

▪ give() ▪ receive()

◦ Actable, with one method: ▪ act()

• You have to create four classes: ◦ Employee ◦ Customer ◦ Money ◦ Donut

Each class has to implement one of the interfaces. Choose wisely!

b) For every class, explain why you made it implement that specific interface.

2. Here is an interface for implementing methods that print messages to the screen:

public interface Printable { private void printToScreen(String msg){ System.out.println(msg); } }

What is wrong with that interface?