## Forum archive 2000-2006

### Michael Gage - Java applet example

by Arnold Pizer -
Number of replies: 0
 Java applet example topic started 9/22/2001; 7:37:51 PMlast post 9/22/2001; 7:37:51 PM
Michael Gage - Java applet example
9/22/2001; 7:37:51 PM (reads: 12472, responses: 0)

## The Java applet example

To obtain this problem

(1 pt) rochesterLibrary/setMAAtutorial/javaappletexample.pg

Java applet example

This problem illustrates how you can embed Java applet code in a WeBWorK example to create an interactive homework problem that could never be provided by a text book.

WeBWorK can use existing javaScript and Java code to augment its capabilities.

###### mathbean applet from David Ecks

The graph above represents the function

where and are parameters.

For each value of find the value of which makes the graph just touch the x-axis.
if a= 2 then
if a= -0.5 then
if a= -2.5 then

Does this relationship between a and b specify b as a function of a? (Yes or No)
Does this relationship between a and b specify a as a function of b? (Yes or No)
Write a formula for calculating this value of from .
b =

WARNINGS
µ¦å{h­
Enter this code
DOCUMENT();loadMacros("PG.pl",           "PGbasicmacros.pl",           "PGchoicemacros.pl",           "PGanswermacros.pl",           ); TEXT(beginproblem(), $BR,$BBOLD, "Java applet example", $EBOLD,$BR,$BR); # define function to be evaluated$a= random(1,3,1);$b= random(-4,4,.1);$c = random(-4,4,1);$x0=random(-2,2,1);$function = FEQ(" ${a}x^2+${b}x +$c "); # This function will be redefined for javaScript as well.sub fp { # define a subroutine to calculate the derivative my$x = shift;	2*$a*$x+$b;}$ans = fp($x0);BEGIN_TEXT$PARThis problem illustrates how you can embed Java applet code in a WeBWorK exampleto create an interactive homework problem that could never be provided by a text book.$PARWeBWorK can use existing$BBOLD javaScript$EBOLD and$BBOLD Java $EBOLD code to augment its capabilities.$HREND_TEXT$javaApplet = <<EOF;<applet code="mathbeans.SliderGraphApplet.class" archive="/courses/system_html/applets/mathbeans.jar" codebase="../classes/" width=400 height=380> <PARAM NAME="variable1" VALUE="a"> <PARAM NAME="variable2" VALUE="b"> <param name="function" value="x^2 +a*x +b"> <param name="limits" value="-2 2 -9 9"></applet> <H6><A HREF="http://math.hws.edu/mathbeans/applets/index.html">mathbean applet from David Ecks</A></H6>EOF# only print out the java applet code when viewing on the screenTEXT(MODES( TeX => " \fbox{ The java applet was displayed here }", HTML =>$javaApplet,));$a1= random(-3,3,.5);$a2= random(-3,3,.5);$a3= random(-3,3,.5);$b1 = ($a1/2)**2; # remember to use ** for exponentiation when # calculating in pure Perl!$b2=  ($a2 / 2)**2;$b3 = ($a3 / 2)**2;ANS(num_cmp($b1, reltol => 10, format=>'%0.2g'));ANS(num_cmp(  $b2, reltol => 10, format=>'%0.2g'));ANS(num_cmp($b3, reltol => 10, format=>'%0.2g'));BEGIN_TEXT$PARThe graph above represents the function$f(x) = x^2 + a x +b$where $$a$$ and $$b$$ are parameters.$PARFor each value of $$a$$ find the value of $$b$$ which makes the graph just touch the x-axis.  $BRif a=$a1 then \{  ans_rule(10) \}$BRif a=$a2 then \{  ans_rule(10) \}$BRif a=$a3 then \{  ans_rule(10) \} $PARDoes this relationship between a and b specify b as a function of a? \{ ans_rule(4) \} (Yes or No)$BRDoes this relationship between a and b specify a as a function of b? \{ ans_rule(4) \} (Yes or No)$BRWrite a formula for calculating this value of $$b$$ from $$a$$.$BRb = \{ ans_rule(40) \}END_TEXTANS(str_cmp('Yes') );ANS(str_cmp('No')  );ANS(fun_cmp('(a/2)^2', vars=>'a'));ENDDOCUMENT();

DOCUMENT();

PGbasicmacros.pl,
PGchoicemacros.pl,
);
TEXT(beginproblem());
$javaApplet = <<EOF; < applet code="mathbeans.SliderGraphApplet.class" archive="/applets/mathbeans.jar" codebase="../classes/" width=480 height=380> < PARAM NAME="variable1" VALUE="a"> < PARAM NAME="variable2" VALUE="b"> < param name="function" value="x^2 +a*x +b"> < param name="limits" value="-2 2 -9 9"> </applet> < H6><A HREF="http://math.hws.edu/mathbeans/applets/index.html">mathbean applet from David Ecks </A> </H6> EOF TEXT(MODES( TeX => " \fbox{ The java applet was displayed here}", Latex2HTML => "\begin{rawhtml}$javaApplet \end{rawhtml}",
HTML_tth => $javaApplet, HTML =>$javaApplet,
));

$a1= random(-3,3,.5);$a2= random(-3,3,.5);
$a3= random(-3,3,.5);$b1 =($a1/2)**2; ANS( num_cmp($b1, reltol => 10, format=>'%0.2g'));
ANS( num_cmp( $b2,reltol => 10, format=>'%0.2g')); ANS( num_cmp($b3, reltol => 10,format=>'%0.2g'));
BEGIN_TEXT
$PAR The graph above represents the function $f(x) = x^2 + a x +b$ where $$a$$ and $$b$$ are parameters.$PAR

For each value of $$a$$ find the value of $$b$$ which makes the
graph just touch the x-axis. $BR if a=$a1 then \{ ans_rule(10) \}$BR if a=$a2 then \{ ans_rule(10) \}$BR if a=$a3 then \{ ans_rule(10) \}
$PAR Does this relationship between a and b specify b as a function of a? \{ ans_rule(4) \} (Yes or No)$BR
Does this relationship between a and b specify a as a function of b? \{
ans_rule(4) \} (Yes or No)$BR Write a formula for calculating this value of $$b$$ from $$a$$.$BR b
= \{ ans_rule(40) \}
END_TEXT
ANS(str_cmp('Yes') ); ANS(str_cmp('No') );
ANS(function_cmp( '(a/2)^2', 'a') );
ENDDOCUMENT();