It is possible to purchase “geek” watches that output the time of day in binary. To illustrate the flexibility of the Model-View-Controller pattern, modify the view class (CounterView) of the previous problem so that the display outputs the counter’s value in binary.
Test your new program by counting values in binary. You should not have to change the model or controller classes.
PROGRAM CODE:
// Main.java (unchanged)
public class Main
{
public static void main(String[] args)
{
// Create a new CounterModel and CounterView
CounterModel model = new CounterModel();
CounterView view = new CounterView();
// Create a new CounterController and set the model and view
CounterController controller = new CounterController();
controller.setModel(model);
controller.setView(view);
// Add the view as an observer to the model
model.addObserver(view);
// Increment the counter ten times to see the binary representation
for (int i = 0; i < 10; i++)
{
controller.increment();
// Add a delay to observe the changes (only for demonstration purposes)
try {
Thread.sleep(1000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
}
}
OUTPUT:
0
1
10
11
100
101
110
111
1000
1001