Instructions: Answer the following questions one at a time. After answering each question, check your answer (by clicking on the check-mark icon if it is available) before proceeding to the next question.
Getting Ready: Before going any further, you should:
DukulatorWindow.jar
or
DukulatorWindow.class
and dukulator.gif
to your directory/project.
Dukulator.java
, IntegerCalculator.java
,
and ExpressionObserver
to your directory/project.
Dukulator
class.
Dukulator
class.
(Note: Depending on your development environment, you may need to
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.
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: Depending on your development environment, you may need to
execute the application from the command line.)
Taxable.java
, AccountDriver.java
,
and Account.java
to your directory/project.
Taxable.java
, AccountDrive.javar
,
and Account.java
.
AccountDriver
?
AccountDriver
.
fred
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 generating any error messages?
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
.
ControllableAlarmClock.jar
or
ControllableAlarmClock.class
and clock.gif
to your directory/project.
ClockDriver.java
and AlarmController.java
to your directory/project.
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
"display" 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 Constructor
*
* 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
interface. (This
interface is part of the Java library that is used to develop
graphical user interfaces. It has one method,
actionPerformed()
. This method is called when
buttons/checkboxes are pressed.)
ActionEvent.getActionCommand()
method in the
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 AlarmController
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 may need to 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;
String ampm;
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 may need to execute the application
from the command line.)
actionPerformed()
method in the
AlarmController
class so that everything
works properly.
Copyright 2021