Chapter 17 Projects: 1. (After 17.3) Changing Color and Alignment

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 14

Chapter 17 Projects

1. [after 17.3] Changing Color and Alignment *:


Write a complete program named Buttons that implements a indo ith three !"ttons # left$ !l"e$
and reset. When the left !"tton is clic%ed$ the indo&s contents 'the three !"ttons( shifts left. When the
!l"e !"tton is clic%ed$ the indo&s !ac%gro"nd color changes to !l"e. When the reset !"tton is clic%ed$
the indo&s contents shifts !ac% to the original center alignment and the indo&s !ac%gro"nd color
changes !ac% to its original color.
)n implementing the reset f"nctionalit*$ don&t tr* to fig"re o"t a color constant that&s "sed for the
indo&s original color +al"e. ,hat&s co"nterprod"cti+e !eca"se the color might !e different on different
comp"ters. )nstead$ retrie+e and sa+e the indo&s original color and then hen the color needs to !e
reset$ "se that sa+ed original color +al"e.
-ample session 'read the indos left to right(:
.riginal displa*: After the Left !"tton is clic%ed:
After the Blue !"tton is clic%ed: After the Reset !"tton is clic%ed:
2. [after 17./] Clic% ,rac%er *:
a) 0asic capa!ilit*:
Write a complete program that monitors a "ser&s clic%s on a grid of nine !"ttons. When a !"tton is
clic%ed$ change its la!el to 1Clic%ed21
-ample session 'read the indos left to right(:
)nitial displa*: After clic%ing on !"tton 34:
After clic%ing on !"tton 35:
6ote:
7o"r program sho"ld contain a class named ClickTracker.
8se a GridLayout manager scheme.
,o promote scalability 'i.e.$ to allo for f"t"re groth($ "se a loop to generate the A$ 0$ and C
la!els and "se another loop to generate the nine !"ttons.
8se an inner class for the listener.
As ala*s:
9imit *o"r "se of class +aria!les and instance +aria!les #"se them onl* if appropriate.
8se appropriate modifiers for *o"r methods. ,he modifiers e&+e disc"ssed are private$
public$ protected$ static$ and final.
8se helper methods if appropriate.
:imic the sample session precisel*. )n partic"lar$ note the indo&s title$ the indo&s si;e$ and
the positions of components.
b) <nhancement:
)mpro+e the loo% of *o"r program !* enhancing the !"tton !orders. )nitiall*$ set the !"ttons& !orders
to BevelBorder.RAISED. When a !"tton is clic%ed$ set its !order to
BevelBorder.LOERED. ,o set a !"tton&s !order$ call set0order and pass in an instantiated
0e+el0order o!ject. =or details$ see -"n&s AP) doc"mentation.
-ample session:
)nitial displa*: After clic%ing !"tton 33:
c) ="rther enhancement:
Add f"nctionalit* to *o"r clic%>trac%er program so that hen a !"tton is clic%ed a second time$ a
arning dialog !o? appears. @int: )n *o"r action!erfor"ed method$ "se the ActionEvent
parameter&s #etActionCo""and method.
-ample session:
After clic%ing a !"tton a second time:
3. [after 17.1A] ,ic>,ac>,oe Bame **:
)mplement a tic>tac>toe game. 8se the simple ,ic,ac,oe program in -ection 17./ as a starting point. Add
the folloing f"nctionalit* to that program:
Chec% for a in. )f there&s a inner$ displa* a dialog !o? ith $ &ins' or O &ins'
Chec% for a cat&s game. )f there&s a cat&s game$ displa* a dialog !o? ith Cat(s #a"e'
)f there&s a in or a cat&s game$ prepare for a ne game !* clearing the !oard and "pdating the
instr"ctions at the top that specif* ho goes first.
)f there&s a in$ "pdate the n"m!er>of>games>on res"lts at the !ottom.
As ala*s$ *o" m"st:
9imit *o"r "se of class +aria!les and instance +aria!les # "se them onl* if appropriate.
8se appropriate modifiers for *o"r methods # private$ public$ static$ andCor final.
8se helper methods if appropriate.
:imic the sample session precisel*. )n partic"lar$ note the indoDs title$ the indoDs si;e$ and the
positions of components.
-ample session 'read the indos left to right(:
)nitial displa*: After clic%ing on the center !"tton:
After filling the !oard as shon: And clic%ing on the last a+aila!le sE"are:
,he "pdated !oard: After filling the !oard as shon:
And clic%ing on the top>right corner: ,he "pdated !oard:
After clic%ing on a sE"are and resi;ing the indo !* mo"se dragging:
4. [after 17.1A] Word .rder Bame$ re+isited **:
,his is an enhanced +ersion of a project presented in Chapter 1/. )n this project$ *o"&ll "se em!edded
la*o"t managers. Create a simple comp"ter game that pro+ides %ids ith ord>ordering practice.
7o"r program sho"ld displa* a list of ords and to te?t !o?es. ,he "ser t*pes to of the ords into
the to te?t !o?es and then presses a Submit !"tton. ,he program ma%es s"re that the ords come
from the ord list and are in correct dictionar* order. @ere is hat the displa* sho"ld loo% li%e after
the "ser enters the ords cat and do#:
)f the "ser no clic%s the Clear !"tton$ the to ords in the te?t !o?es sho"ld disappear$ and the "ser
sho"ld !e a!le to repeat the e?ercise. 6otice the 17o" are correct21 message on the last ro. )nitiall*$
there sho"ld !e nothing in this location. When the "ser clic%s the -"!mit !"tton$ one of the folloing
messages sho"ld appear here the 17o" are correct21 is shon:
)f there is nothing in either of the to te?t !o?es$ print:
Enter &ords in bot) bo*es.
)f neither of the to entered ords is in the list$ print:
+eit)er entry is in t)e &ord list.
)f the first ord is not in the list$ print:
,irst entry not in &ord list - c)eck spellin#.
)f the second ord is not in the list$ print:
Second entry not in &ord list - c)eck spellin#.
)f !oth ords are from the list !"t are the same$ print:
.ou entered t)e sa"e &ords. Try a#ain.
)f !oth ords are from the list !"t are in the rong order$ print:
ron#. Try a#ain.

)f the "ser enters to ords from the ord list$ *o"r program sho"ld call the Strin# class&s
co"pareTo method to determine hether the ords are in correct dictionar* order.
=or the o+erall indo$ "se a BorderLayout$ and in the EST region p"t a /Label ith F
spaces. ,his ill pro+ide a "niform space on the left side of the displa*. )n the CE+TER region$ p"t a
/!anel called "ain!anel$ and "se a one>col"mn GridLayout for it. ,his panel sho"ld hold all
of the other B8) components:
P"t a /Label called )eadin# in the first ro$ and "se the folloing set,ont method call to
ma%e the heading larger than normal:
)eadin#.set,ont0)eadin#.#et,ont01.derive,ont023f114
P"t another panel ith a one>col"mn GridLayout in the second ro$ and p"t instr"ction la!els$
ith appropriate lines$ in this panel.
P"t another panel ith a fi+e>col"mn GridLayout in the third ro$ and p"t thirt* la!els ith
the 3A ords in this panel.
P"t another panel ith a three>ro GridLayout in the fo"rth ro. )n this panel$ p"t the first
te?t !o?$ the 1goes !efore1 la!el$ the second te?t !o?$ the to !"ttons$ and the response la!el.
Go not "se the set!referredSi5e method in this implementation.
5. [after 17.1A] ,hermal Giff"sion in a Bro"nd>-o"rce @eat P"mp&s Well ***:
Write a program that calc"lates temperat"res in the earth aro"nd a gro"nd>so"rce heat>p"mp ell$
o+er the co"rse of one *ear.
As an instance +aria!le$ declare a 4H element double67 pointTe"p arra* to hold the
instantaneo"s temperat"re in the earth at different distances '31$ 71$ 111$ 1F1$ 1I1$ etc.$ on a 41
spacing( from the center of the ell.
)n the "ain method$ declare a local double ti"e +aria!le for the ho"r and a local
double67 av#!ointTe"p arra* for a+erage temperat"re at the 4H points o+er a />da* time
period. ,hen:
)nstantiate an o!ject of the class *o" are defining.
9oop thro"gh /A time periods. )n each time period do the folloing:
)nitiali;e all 4H a+erage temperat"res to ;ero.
9oop thro"gh 144 ho"rs '/ da*s($ and for each ho"r$ do the folloing:
)ncrement the time !* one ho"r.
Call a load method to comp"te )eat,lo& J 0,8C@r going into the ell at the c"rrent
ho"r.
Call a diffuse method ith the j"st>comp"ted )eat,lo& as an arg"ment to comp"te
the +al"es for the elements in the pointTe"p arra*.
Acc"m"late co"putedTe"perature 8 9:: in the each element of the a+erage
temperat"re arra*$ so that after 144 ho"rs this arra* has the a+erage temperat"re at all
points for the />da* time period ending at the c"rrent ho"r.
Call a display method to displa* the res"lts for the c"rrent time period.
a) )mplement a constr"ctor$ a load method$ a diffuse method$ and a display method to
displa* the comp"ted res"lts in a ta!"lar fashion in the Command Prompt indo.
@a+e the constr"ctor initiali;e all temperat"res in the pointTe"p arra* to F5 degrees =.
)mplement the load method$ "sing this algorithm to calc"late the net heat flo into the gro"nd
in each ho"rl* period:
=irst comp"te the heat flo into the !"ilding d"e to eather$ internal electrical "sage$ and
people heat$ "sing this form"la:
)eat,lo& J ;4AAA - H5$AAA < cos0HK < ho"r 8 03/A < H411
= 5$AAA < cos0HK < ho"r 8 01A < H411 = 1H$AAA < sin0HK < 0ho"r # 1A1 8 H4 1L
,he constant represents net ann"al a+erage space cooling. '.n a+erage$ the space needs a
small amo"nt of heat.( ,he three sin"soidal terms correspond to ann"al +ariation$ a t*pical
1A>da* eather c*cle$ and dail* +ariation.(
,hen add fan>motor heat ith this form"la:
)eat,lo& => ?.?: < @at).abs0)eat,lo&14
,hen s"!tract heat reco+ered to heat domestic hot ater ith this form"la:
)eat,lo& => ;9???4
,hen$ if net heat=lo is less then ;35$AAA$ set it eE"al to ;35$AAA.
,hen$ add compressor>motor heat ith this form"la:
)eat,lo& => ?.9A < @at).abs0)eat,lo&14
=inall* add gro"ndater>p"mp>motor heat ith this form"la:
)eat,lo& => ?.?: < @at).abs0)eat,lo&14
)mplement the diffuse method ith a single parameter$ )eat,lo&$ to "pdate the temperat"re
profile in the gro"nd at ho"rl* inter+als. 8se these constants:
double dept) > B??.?4 88 feet
double conductivity > ?.AC4 88 BTD8Er8ft8de#,
double density > 9:?4 88 lb8cuft
double specificEeat > ?.9B4 88 BTD8lb8de#,
double diffusion >
conductivity 8 0density < specificEeat14 88 sFft8)our
double &ellRadius > ?.2G4 88 ft
double delta$ > ?.CC4 88 ft
double factor > diffusion < deltaT 8 0delta$ < delta$14

:odel the radial diff"sion process li%e this:
=irst$ "se )eat,lo& to esta!lish the ne ell temperat"re 'pointTe"p6?7( in terms of
the pre+io"s temperat"re at the ne?t point and the a!o+e constants$ "sing this form"la:
pointTe"p6?7 J pointTe"p697 = )eat,lo& 8
0HK < dept) < conductivity < loge01 = delta$ 8 &ellRadius11.
,hen$ for points 1 thro"gh 4A$ "se the folloing form"la to calc"late the ne temperat"re at
each s"ccessi+e point in terms of pre+io"s temperat"res at that point and the points !efore
and after it:
pointTe"p6H7 J pointTe"p6H7 = factor <
001 ; A.F8H1 < pointTe"p6H;97; H.A < pointTe"p6H7 =
01 M A.F 8H1 < pointTe"p6H=97(
@oe+er$ immediatel* !efore "pdating point 4A$ set the +al"e at point 41 eE"al to the
pre+io"s +al"e at point 4A. ,his esta!lishes a pla"si!le o"tside !o"ndar* condition.
)mplement the display method. )t sho"ld recei+e inp"ts for three parameters$
periodLen#t)$ period+u"ber$ and a reference to "ain&s av#!ointTe"p arra*$ and it
sho"ld print this res"lt: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7 F7 F7 F7 F7
timeJ 1HI/ 47 FA FH FH F3 F3 F4 F4 F4 FF FF FF FF FF FF F/ F/ F/ F/ F/ F/
F/ F/ F/ F/ F7 F7 F7 F7 F7 F7 F7 F7 F7 F7 F7 F7 F7 F7 F7 F7 F7
timeJ 144A 4/ FA F1 FH F3 F3 F4 F4 F4 F4 FF FF FF FF FF FF F/ F/ F/ F/ F/
F/ F/ F/ F/ F/ F/ F/ F7 F7 F7 F7 F7 F7 F7 F7 F7 F7 F7 F7 F7 F7
timeJ 1F54 47 F1 FH F3 F3 F4 F4 F4 F4 FF FF FF FF FF FF FF F/ F/ F/ F/ F/
F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F7 F7 F7 F7 F7 F7 F7 F7 F7 F7
timeJ 17H5 4I FH FH F3 F3 F4 F4 F4 F4 FF FF FF FF FF FF FF FF F/ F/ F/ F/
F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/
timeJ 157H 45 F1 FH F3 F4 F4 F4 F4 FF FF FF FF FF FF FF FF FF F/ F/ F/ F/
F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/
timeJ HA1/ F3 F4 F4 F4 F4 F4 F4 FF FF FF FF FF FF FF FF FF FF FF F/ F/ F/
F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/
timeJ H1/A FH F3 F4 F4 F4 F4 FF FF FF FF FF FF FF FF FF FF FF F/ F/ F/ F/
F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/
timeJ H3A4 F4 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF F/ F/ F/ F/ F/
F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/
timeJ H445 F7 F/ F/ F/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
timeJ 3/AA 7A /4 /H /1 /A /A FI FI FI FI F5 F5 F5 F5 F5 F7 F7 F7 F7 F7 F7
F7 F7 F7 F7 F7 F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/
timeJ 3744 7H // /4 /3 /H /1 /A /A /A FI FI FI F5 F5 F5 F5 F5 F7 F7 F7 F7
F7 F7 F7 F7 F7 F7 F7 F7 F7 F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/ F/
timeJ 3555 7F /7 /F /3 /H /1 /1 /A /A FI FI FI FI F5 F5 F5 F5 F5 F5 F7 F7
F7 F7 F7 F7 F7 F7 F7 F7 F7 F7 F7 F7 F7 F7 F7 F7 F/ F/ F/ F/ F/
timeJ 4A3H 7H // /F /3 /H /H /1 /1 /A /A /A FI FI FI FI F5 F5 F5 F5 F5 F5
F5 F7 F7 F7 F7 F7 F7 F7 F7 F7 F7 F7 F7 F7 F7 F7 F7 F7 F7 F7 F7
timeJ 417/ 77 /I // /F /3 /3 /H /1 /1 /A /A /A FI FI FI FI F5 F5 F5 F5 F5
F5 F5 F5 F7 F7 F7 F7 F7 F7 F7 F7 F7 F7 F7 F7 F7 F7 F7 F7 F7 F7
timeJ 43HA 7F /5 // /4 /3 /H /H /1 /1 /1 /A /A /A FI FI FI FI FI F5 F5 F5
F5 F5 F5 F5 F5 F5 F5 F7 F7 F7 F7 F7 F7 F7 F7 F7 F7 F7 F7 F7 F7
timeJ 44/4 7/ /I /7 /F /4 /3 /3 /H /H /1 /1 /A /A /A /A FI FI FI FI FI F5
F5 F5 F5 F5 F5 F5 F5 F5 F5 F5 F5 F7 F7 F7 F7 F7 F7 F7 F7 F7 F7
timeJ 4/A5 75 7A /7 /F /4 /3 /3 /H /H /1 /1 /1 /A /A /A /A FI FI FI FI FI
FI F5 F5 F5 F5 F5 F5 F5 F5 F5 F5 F5 F5 F5 F5 F5 F5 F5 F5 F5 F5
timeJ 47FH 74 /5 // /F /4 /3 /3 /H /H /H /1 /1 /1 /A /A /A /A FI FI FI FI
FI FI FI FI F5 F5 F5 F5 F5 F5 F5 F5 F5 F5 F5 F5 F5 F5 F5 F5 F5
timeJ 45I/ 75 7A /5 // /F /4 /3 /3 /H /H /1 /1 /1 /1 /A /A /A /A /A FI FI
FI FI FI FI FI FI FI F5 F5 F5 F5 F5 F5 F5 F5 F5 F5 F5 F5 F5 F5
timeJ FA4A 74 /5 // /F /4 /4 /3 /3 /H /H /1 /1 /1 /1 /A /A /A /A /A /A FI
FI FI FI FI FI FI FI FI FI FI FI F5 F5 F5 F5 F5 F5 F5 F5 F5 F5
timeJ F154 74 /I /7 // /F /4 /3 /3 /H /H /H /1 /1 /1 /1 /A /A /A /A /A /A
/A FI FI FI FI FI FI FI FI FI FI FI FI FI FI FI FI FI FI FI FI
timeJ F3H5 7F /5 // /F /4 /4 /3 /3 /H /H /H /1 /1 /1 /1 /1 /A /A /A /A /A
/A /A /A FI FI FI FI FI FI FI FI FI FI FI FI FI FI FI FI FI FI
timeJ F47H 7A // /F /4 /4 /3 /3 /3 /H /H /H /H /1 /1 /1 /1 /1 /A /A /A /A
/A /A /A /A /A /A FI FI FI FI FI FI FI FI FI FI FI FI FI FI FI
timeJ F/1/ 73 /5 // /F /4 /3 /3 /3 /H /H /H /H /1 /1 /1 /1 /1 /1 /A /A /A
/A /A /A /A /A /A /A /A /A FI FI FI FI FI FI FI FI FI FI FI FI
timeJ F7/A /5 /F /4 /3 /3 /3 /H /H /H /H /H /1 /1 /1 /1 /1 /1 /1 /1 /A /A
/A /A /A /A /A /A /A /A /A /A /A /A /A /A /A FI FI FI FI FI FI
timeJ FIA4 /7 /F /4 /4 /3 /3 /H /H /H /H /H /1 /1 /1 /1 /1 /1 /1 /1 /A /A
/A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A
timeJ /A45 /7 /4 /3 /3 /H /H /H /H /H /1 /1 /1 /1 /1 /1 /1 /1 /1 /1 /1 /A
/A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A
timeJ /1IH /H /H /H /H /H /H /H /1 /1 /1 /1 /1 /1 /1 /1 /1 /1 /1 /1 /1 /A
/A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A
timeJ /33/ /4 /H /H /H /H /1 /1 /1 /1 /1 /1 /1 /1 /1 /1 /1 /1 /1 /1 /1 /A
/A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A
timeJ /45A FI /A /A /A /A /1 /1 /1 /1 /1 /1 /1 /1 /1 /1 /1 /1 /1 /A /A /A
/A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A
timeJ //H4 F5 /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A
/A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A
timeJ /7/5 F5 FI FI FI /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A
/A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A
timeJ /I1H F4 F7 F5 F5 FI FI FI /A /A /A /A /A /A /A /A /A /A /A /A /A /A
/A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A
timeJ 7AF/ FF F7 F5 F5 FI FI FI FI FI FI /A /A /A /A /A /A /A /A /A /A /A
/A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A
timeJ 7HAA FH FF F/ F7 F5 F5 F5 FI FI FI FI FI FI /A /A /A /A /A /A /A /A
/A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A
timeJ 7344 F1 FF F/ F7 F7 F5 F5 F5 FI FI FI FI FI FI FI FI /A /A /A /A /A
/A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A
timeJ 7455 FA F4 FF F/ F7 F7 F5 F5 F5 F5 FI FI FI FI FI FI FI FI FI /A /A
/A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A
timeJ 7/3H 47 F3 F4 FF F/ F7 F7 F7 F5 F5 F5 F5 FI FI FI FI FI FI FI FI FI
/A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A
timeJ 777/ 45 F3 F4 FF F/ F/ F7 F7 F7 F5 F5 F5 F5 F5 FI FI FI FI FI FI FI
FI FI FI FI /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A /A
timeJ 7IHA 4/ F1 F3 F4 FF F/ F/ F7 F7 F7 F5 F5 F5 F5 F5 F5 FI FI FI FI FI
FI FI FI FI FI FI FI /A /A /A /A /A /A /A /A /A /A /A /A /A /A
timeJ 5A/4 4/ F1 F3 F4 FF F/ F/ F/ F7 F7 F7 F5 F5 F5 F5 F5 F5 FI FI FI FI
FI FI FI FI FI FI FI FI FI FI FI FI /A /A /A /A /A /A /A /A /A
timeJ 5HA5 4/ F1 F3 F4 FF FF F/ F/ F/ F7 F7 F7 F7 F5 F5 F5 F5 F5 F5 FI FI
FI FI FI FI FI FI FI FI FI FI FI FI FI FI FI FI FI FI FI FI FI
timeJ 53FH 43 FA FH F3 F4 FF FF F/ F/ F/ F7 F7 F7 F7 F5 F5 F5 F5 F5 F5 F5
F5 FI FI FI FI FI FI FI FI FI FI FI FI FI FI FI FI FI FI FI FI
timeJ 54I/ 4F FA FH F3 F4 FF FF F/ F/ F/ F/ F7 F7 F7 F7 F5 F5 F5 F5 F5 F5
F5 F5 F5 FI FI FI FI FI FI FI FI FI FI FI FI FI FI FI FI FI FI
timeJ 5/4A 43 4I F1 F3 F3 F4 FF FF F/ F/ F/ F/ F7 F7 F7 F7 F7 F5 F5 F5 F5
F5 F5 F5 F5 F5 F5 FI FI FI FI FI FI FI FI FI FI FI FI FI FI FI
<ach time is c"m"lati+e ho"rs from the !eginning of the standard *ear. ,here is one line of
'rapped aro"nd( data for each period of 144 ho"rs or si? da*s. ,he ro of integers that follos
each time is a profile of the a+erage =ahrenheit temperat"re in the earth aro"nd the ell d"ring
the period ending at the indicated time. ,he 4H temperat"res printed for each time inter+al are
ordered !* distance from the center of the ell$ ith the first point at the ell s"rface and the last
point almost 14 ft from the ell.
b) <nhance the program ritten in part a( to ma%e it disla* the o"tp"t in B8) format.
:a%e the class e?tend /,ra"e.
:odif* the constr"ctor to pro+ide a title and set the si;e for a 5AA x 7AA displa* indo$ that ill
loo% li%e this:
Call a createContents method to config"re the displa* li%e this:
8se an o+erall BorderLayout scheme.
)n BorderLayout.+ORTE$ insert a /!anel "sing ,lo&Layout.LE,T that incl"des a
Label ith the indicated te?t folloed !* the 7 /Labels for the 7 temperat"re n"m!ers.
8se a call to a helper method called color to set the 'foregro"nd( coloring for each n"m!er
to match its temperat"re +al"e.
)n BorderLayout.EST$ insert a /!anel "sing GridLayout0?I21. 8se a loop to
insert N9a!els for month a!!re+iations in the first col"mn and elements of a /A>element
&ellTe"p arra* in the second col"mn.
)n BorderLayout.CE+TER$ insert a /!anel "sing GridLayout0?I:21. ,hen "sing
nested for loops$ fill that /!anel ith a /A x 4H arra* of /!anel elements.
)n BorderLayout.SODTE$ insert a /!anel "sing GridLayout0?I::1. ,hen to that
/!anel add little /Labels that insert the OftP notation and appropriate n"m!ers at
appropriate places along the !ottom of the displa*.
)mplement a color method that translates a temperat"re n"m!er into a color. 8se the folloing
algorithm:
red J 'deg= # /A( 8 3A
green J 1.A # a!s'deg= # /A( 8 3A
!l"e J 'IA # deg=( 8 3A
Whene+er an* of these three form"las prod"ces a +al"e greater than 1.A$ set it eE"al to 1.A$ and
hene+er it prod"ces a n"m!er less than A.A$ set it eE"al to A.A. ,his algorithm sho"ld prod"ce a
color range that progresses fairl* "niforml* from p"re !l"e at 3A
o
=$ thro"gh green at /A
o
=$ to
p"re red at IA
o
=.
Create a different display method that has onl* to parameters$ period+u" and a reference
to "ain&s av#!ointTe"p arra*. :a%e this method displa* the res"lts as B8) rather than
Command Prompt te?t. Pro+ide the appropriate n"m!er for the +ertical temperat"re la!el on the
left side of the displa* !* "sing /Label&s setTe*t method to cop* the c"rrent +al"e from
pointTe"p6?7. )n a for loop that steps thro"gh points AQ41$ "se /!anel&s
setBack#roundColor method to translate each pointTe"p +al"e to an appropriate color
for each point in the profile 'a small rectang"lar area in the C<6,<R part of the displa*( for the
c"rrent time inter+al.

You might also like