Daniel Bednarski
CS 202
Project 3
Microwave Oven
Version 2.0
Project Design
Project
Goal: To provide a functional GUI microwave simulation. The program will take
user input through the graphical user interface through interaction with
buttons and menus. The user will be able to set and clear time, choose a preset
from 6 of the most commonly cooked items, will have a light turn on when the
cooking starts and will include a help menu with an 'about' box.
A. MicrowaveGUI Class
1) Import javax.swing.*
and java.awt.*
2) Main Method
a. Create frame object of MicrowaveContainer
b. Determine screen size to center
microwave gui.
c. Make basic settings such as
microwave size and visible.
B. MicrowaveContainer class
1) Extends JFrame
Implements ActionListener
2) Import javax.swing.*
and java.awt.*
3) Default Constructor
a. Create microwave container and set
border layout
b. Create a menu bar with help menu
option and About menu item
c. Create a control bar with border
layout and set inside east section of microwave container
i.
Create
text field with timer values. Default is 00:00
1. Set inside the north section of the
control panel
ii.
Create
key pad with numbers 0-9, clear timer, set timer, start timer, start cooking
and stop buttons
1. Set action listeners for each
2. Set inside the center section of the
control panel
3. Use an array to construct numbers
1-9
iii.
Create
presets menu for 6 most common items: flash, beverage, popcorn, soup, dinner
and defrost.
1. Set action listeners for each
2. Set inside the south section of the
control panel
4) actionPerformed Method
a. Use if statements to determine what
even occurred.
b. For each button pressed, print out
what button it is
i.
In
version 2.1, the print actions will be replaced with method calls from the testMicrowaveOven class
c. If the About
menu item is the event, the aboutContent method of
the AboutBox will be called.
C. AboutBox Class
1) Import javax.swing.*
and java.awt.*
2) aboutContent Method
a. create a JOptionPane
and insert it into a Jdialog box.
b. JoptionPane will say my name, instructor's
name, class name and a description of the program.
c. Set size, as visible, title and to
hide on close
D. TestMicrowaveOven Class
1) Text based user interface for the
microwave oven from version 1. This will be phased out in version 2.1 when it
is integrated into the GUI event handlers.
2) Create oven1 object of the MicrowaveOven class
3) Create time1 object of Time class
4) Print operating menu: set timer,
start, stop and presets
Collect keyboard input
5) If user chooses to set time
a. Collect timer input (timeString)
b. Call setTimer
method of oven1 object
6) If user chooses to view the presets
menu
a. Call choosePresets
method of oven1 object
i.
Returns
value of timeString
b. Call setTimer
method of oven1 object.
7) If user chooses to start cooking
a. Checks if the time has been set. If
not, presents an error.
b. If a time has been set, call startCook method of oven1 object
8) If user chooses timer only
a. Checks if the time has been set. If
not present an error
b. If a time has been set, call timerOnly method of oven1 object
9) If user choose stop program closes
a. In version 2.1, the cook or timer
methods will be halted but the program will not be closed.
10) If user chooses clear, it will call
the clearTimer method of the oven1 object
E. MicrowaveOven class
1) Constructor input: time1 object of Time class
2) setTimer method
a. call setTime
method of time1 object
b. set minutes and seconds through a
call to getMinutes and getSeconds
methods of time1 object
3) clearTimer method
a. call getSound
method (beeps)
b. call setTimer
method
i.
pass
"00:00" as time value
c. print confirmation message
4) choosePresets method
a. new String presetChoice
b. new String MMSS (minutes: seconds
format)
c. solicit user input (presetChoice): flash, beverage, popcorn, soup, dinner plate
or defrost
d. if presetChoice
= flash
i.
MMSS
= 00:15
e. If presetChoice
= beverage
i.
MMSS
= 01:00
f.
If
presetChoice = popcorn
i.
MMSS
= 01:30
g. If presetChoice
= soup
i.
MMSS
= 02:00
h. If presetChoice
= dinner
i.
MMSS
= 03:00
i.
If
presetChoice = defrost
i.
MMSS
= 05:00
j.
Return
MMSS
5) startCook method
a. calls getSound
method (beeps)
b. call lightSwitch(on)
method
c. print confirmation method that
cooking started
d. call runTimer
method
e. call lightSwitch(off)
method
f.
call
getSound method (beeps)
g. print confirmation method that
cooking stopped
h. call clearTimer
to set timer at 00:00
6) timerOnly method
a. calls getSound
method (beeps)
b. calls runTimer
method
c. calls getSound
method (beeps)
d. prints confirmation message that
timer is done
e. calls clearTimer
to set timer at 00:00
7) getSound method
a. input: number of beeps
b. for (int i = 0; i< # of beeps; i++)
i.
prints
"beep"
c. version 2.1 will have an audible
beep
8) lightSwitch method
a. input: lightSwitchValue
b. if lightSwitchValue
= 0
i.
light
turns off
c. if lightSwitchValue
= 1
i.
light
turns on
9) runTimer method
a. while minutes >0
i.
while
seconds > 0 && minutes >= 0
1. pause program for a second using Thread.sleep(1000)
2. call decrementSecond
method
3. print value from toString for time1
object
ii.
pause
program for a second using Thread.sleep(1000)
iii.
call decrementMinute
iv.
if
minutes >=0
1. call resetSeconds
method
2. print value from toString for time1
object
Time Class
1) Import java.util.StringTokenizer
and java.util.NoSuchElementException
2) Constructor input: MMSS
3) SetTime Method
a. input
b. call checkRange
method
i.
catch
exception caused by incorrect format
ii.
Print
error message if incorrect
4) CheckRange Method
a. Throws no suchelementexception
b. Convert string MMSS to integers for
minutes and seconds
i.
StringTokenizer stTimeString = new StringTokenizer (MMSS, ":")
ii.
String
stMinute = stTimeString.nexttoken()
iii.
String
stSecond = stTimeString.nexttoken()
iv.
Minutes
= Integer.parstInt(stMinute)
v.
Seconds
= Integer.parseInt(stSecond)
c. If minutes > 59 or < 0
i.
Minutes
= 0
d. If seconds >59 or < 0
i.
Seconds
= 0
5) GetMinutes method
a. Returns minutes
6) GetSeconds method
a. Returns seconds
7) ToString method
a. if (minutes < 10 &&
seconds <10)
i.
return
"0" + minutes + ":0" + seconds;
b. else if (minutes >10 &&
seconds < 10)
i.
return
minutes + ":0" + seconds;
c. else if(minutes < 10 && seconds
>= 10)
i.
return
"0" + minutes + ":" + seconds;
d. else if (minutes > 10 && seconds
> 10)
i.
return
minutes + ":"+ seconds;
e. else
i.
return
"00:00";
8) decrementMinute method
a. return --minutes
9) decrementSeconds method
a. return --seconds
10) resetSeconds method
a. return seconds = 59