Instructions: Answer as many of the following questions as you can during the lab period. If you are unable to complete the assignment during the lab period it is strongly recommended that you complete it on your own.
Getting Ready: Before going any further, you should:
Dukulator
class.
Dukulator
class.
(Note: You should execute the application
from the command line.)
Dukulator
did not work properly?
ExpressionObserver
interface and the
IntegerCalculator
class.
ExpressionObserver
is an object that
knows how to evaluate a String
representation of an
expression and return a String
representation of the result.
Add a "clause" to the declaration of the IntegerCalculator
class so that it claims to implement this interface.
IntegerCalculator
class so that
it actually does implement the ExpressionObserver
interface. This method must use the calculate()
method and must return the
String
"Error" if the calculate()
method
throws an exception or the String
representing the value of the expression if there is no errer.
DukulatorWindow
is a GUI window that contains a
"soft" numeric keypad and a one-line display. Familiarize yourself
with the behavior of this class by reading the descriptions
of the following methods:
/**
* Default Constructor
*/
public DukulatorWindow()
/**
* Set the ExpressionObserver that should be notified when
* the = button is pressed
*
* @param observer The observer to notify
*/
public void setExpressionObserver(ExpressionObserver observer)
IntegerCalculator
class is now an
ExpressionObserver
you can now tell a
DukulatorWindow
object to call your
IntegerCalculator
when the = button
is pressed.
Modify the Dukulator
class so that it constructs
an IntegerCalculator
and associates it with the
DukulatorWindow
.
Dukulator
class.
(Note: You should execute the application
from the command line.)
Taxable
, AccountDriver
,
and Account
.
AccountDriver
?
AccountDriver
.
barney
is declared to be a Comparable
but instantiated as an Account
, and wilma
is declared to be a Taxable
but instantiated as an
Account
. Why does AccountDriver
compile without errors?
main()
method of AccountDriver
,
after the initialization statements, add a call to summarize()
passing it the object named barney
.
AccountDriver
.
summarize()
method that is passed an
Account
object.
AccountDriver
.
summarize()
method that is
passed an Account
object. (That is, the
AccountDriver
class should again have three
summarize()
methods.
summarize()
so that it now passes
fred
instead of barney
.
AccountDriver
.
ClockDriver
class.
ClockDriver
class. (Note: The information at the
bottom of the clock shows the state of the alarm settings. The
buttons/checkbox are for changing the alarm settings.)
ControllableAlarmClock
is a GUI window that contains a
"displays" and "controls" for an alarm clock. Familiarize yourself
with the behavior of this class by reading the descriptions
of the following methods:
/**
* Default Constructor
*
* Construct an AlarmClock for your "home" city
*/
public ControllableAlarmClock()
/**
* Explicit Value Constuctor
*
* Construct an AlarmClock for the given city
* (Note: Not all city names are recognized)
*/
public ControllableAlarmClock(String city)
/**
* Add an ActionListener to the buttons on the alarm setter
*
* @param listener The ActionListener
*/
public void addActionListener(ActionListener listener)
/**
* Get the AMPM setting on the alarm
*
* @return "AM" or "PM"
*/
public String getAlarmAMPM()
/**
* Get the hour setting on the alarm
*
* @return The hour setting on the
*/
public int getAlarmHour()
/**
* Get the minute setting on the alarm
*
* @return The minute setting on the
*/
public int getAlarmMinute()
/**
* Is the alarm on?
*
* Note: This method does not check to see if the alarm is currently
* beeping. It checks to see if the alarm will beep when at
* the appropriate time
*
* @return true if the alarm is currently on; false otherwise
*/
public boolean isAlarmOn()
/**
* Set the hour of the alarm
*
* @param hour The hour of the alarm
*/
public void setAlarmHour(int hour)
/**
* Set the minute of the alarm
*
* @param minute The minute of the alarm
*/
public void setAlarmMinute(int minute)
/**
* Set the AM/PM of the alarm
*
* @param ampm "AM" for before noon, "PM" for noon and after
*/
public void setAlarmAMPM(String ampm)
/**
* Turn the alarm off
*/
public void turnAlarmOff()
/**
* Turn the alarm on
*/
public void turnAlarmOn()
ActionListener
actionPerformed()
. This method is called when
buttons/checkboxes are pressed.)
ActionEvent.getActionCommand()
java.awt.event.ActionEvent
class. (This class is
also part of the Java library that is used to develop graphical
user interfaces. This method returns a String
that
can be used to identify the button/checkbox that was pressed.)
actionPerformed
method in the
AlarmController
class so that it prints
the String
description of the button/checkbox
that was pressed.
(Note: At this point, the AlaramController
will
not respond to buttons/checkboxes. You'll fix that shortly.)
ClockDriver
class. It must now also:
AlarmController
object named
controller
.controller
(passing the constructor
clock
).clock
object's addActionListener()
method, passing it controller
.ClockDriver
class.
(Note: You should execute the application
from the command line.)
String
is associated with each button/checkbox
in the ControllableAlarmClock
?
actionPerformed
method in the AlarmController
class:
int value;
if (ac.equals("HOUR_DOWN"))
{
value = clock.getAlarmHour();
value--;
if (value < 1) value = 12;
clock.setAlarmHour(value);
}
else if (ac.equals("HOUR_UP"))
{
value = clock.getAlarmHour();
value++;
if (value > 12) value = 1;
clock.setAlarmHour(value);
}
AlarmController
class
and execute and test the ClockDriver
class.
(Note: You should execute the application
from the command line.)
actionPerformed()
method in the
AlarmController
class so that everything
works properly.
Copyright 2011