[NHS Homepage] [Academic Cooperative Grant Page] [Computer Programming 2] [Syllabus]


CompoundOp.java


/*CompoundOp.java 
This applet will demonstrate compound operations

& ltapplet
code=CompoundOp
width=200
height=200 >
< /applet >


*/


import java.applet.*;
import java.awt.*;



public class CompoundOp extends Applet
 {

   TextArea Result=new TextArea(8,20);
   Button ShowIt=new Button("Determine the output.");
	
	public void init()
    {

      add(ShowIt);
	  add(Result);
   	}

public boolean action (Event thisEvent, Object thisObject)
{

   int x = 3;
   int y = 10;
   int z = 1;  
   int j = -2;
   int a = 5;
   int b = 7;
   j = j + y;
   x += y;// This means the same as x = x + y
   z -= x;
   y -= b + z; // This means y = y - (b + z)
   a *= y;
   b /= 3;
   Result.appendText("x="+x+"");
   Result.appendText("y="+y+"\n");
   Result.appendText("\nz= "+z+" **** j= "+j+" ");
   Result.appendText("\na= "+a+" **** b= "+b+" ");
   Result.appendText("zzz "+(x + y *2 + 5)+" !!!\n");
   Result.appendText("\n\n "+j+"##"+z+"www");
   return true;
}

}



Output for CompoundOp.java