# Math 151 Honors-Section 202 Maplet Project # Half-life of Element X # Randy Faas and Ashley Moore # November 20, 2005 restart: with(Maplets): with(Maplets[Tools]): with(Maplets[Elements]): StartEngine(); randomize(): # This section of code creates the maplet window. It makes a window with a new problem button, a shutdown button, a check answer button, a show answer button, 2 question text fields and an answer field. HalfLife:=Maplet(onstartup = RunWindow(MAIN), Window[MAIN]('title'="Half-life of Element X", defaultbutton=Check, [ [ Button("New Problem", Evaluate('function'="ask")), " ", Button("Hint", Evaluate('function'="hint")), Button("Quit", Shutdown()) ], [ TextField['question1']("The Half-life of Element X is T years.", 'width'=40, 'editable'='false') ], [ TextField['question2']("If you start out with A0 grams, how much is left after t years?", 'width'=40, 'editable'='false') ], [ "Answer: ", TextField['answer']('width'=25) ], [ Button[Check]("Check Answer", Evaluate('function'="check")), " ", Button("Show Answer", Evaluate('function'="show")) ], [ TextField['reply'] ('width'=40, 'editable'='false') ], ["Programmers: Faas & Moore Copyright P. Yasskin 2005" ] ] ) ): # This part defines the problem and asks the question in the text fields. ask:=proc() global correcthalflife; local h, t, a, randh, randt, randa; randh:=rand(5..10): randt:=rand(5..10): randa:=rand(100..200): h:=randh(); t:=randt(); a:=randa(); while (h=t) do h:=randh(); end do; correcthalflife:=a*(1/2)^(t/h); Set('question1'=cat( "The Half-life of Element X is ", convert(h,string), " years." )); Set('question2'=cat("If you start out with ", convert(a,string), " grams, how much is left after ", convert(t,string), " years?" )); Set('reply'=""); Set('answer'=""); end proc: # This section creates the procedure for the check answer button. check:=proc() global correcthalflife; local userhalflife; userhalflife:=Get('answer'::'realcons', corrections=true, update=true): if evalf(abs(userhalflife-correcthalflife)) < 10^(-2) then Set('reply'="You're krunk! Go again!") else Set('reply'="Sorry, you're wrong. Try again.") end if; end proc: # This section creates the procedure for the show answer button. show:=proc() global correcthalflife; Set(answer=correcthalflife); Set('reply'=""); end proc: # This section creates the procedure for the hint. hint:=proc() Set('reply'=" A = A0 * (1/2)^(t/T)"); end proc: Display(HalfLife);