Java Reference
In-Depth Information
The
CounterView
class should simply take an input counter value and print it on
the console screen.
The
CounterModel
class should have a variable that represents the counter's
value. The
Increment
method increments the counter by one and calls
CounterView
's
Display
method.
The
CounterController
class takes a start and end value that is specified by the
user.
CounterModel
is then initialized with the start value. When the
Start
method is invoked it calls
CounterModel
's increment method once per second
until
endValue - startValue
seconds have elapsed.
You will need to implement additional variables or methods in addition to those
shown above in order to create the linkages between classes.
You can use the method call
Thread.sleep(1000)
to make the
CounterController
wait for one second. The call must be placed inside a
try/
catch
block.
Test your program with a
main
method that counts several different ranges of
values.
5.
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.
6.
Recode the
QuickSort
class implementation by adding two efficiency improve-
ments to the method
sort
: (1) Eliminate the calls to
join
, since it accomplishes
nothing. (2) Add code for the special case of an array of exactly two elements and
make the general case apply to arrays of three or more elements.
7.
Redo the
QuickSort
class so that it chooses the splitting point as follows: The
splitting point is the middle (in size) of the first element, the last element, and an
element at approximately the middle of the array. This will make a very uneven
split less likely.
8.
Redo the
QuickSort
class to have the modifications given for projects 6 and 7.