Heap Stack Diagram from Code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • seper254
    New Member
    • Apr 2010
    • 1

    Heap Stack Diagram from Code

    Hey I am in the middle of Java and I am having trouble drawing heap stack diagrams from code. I have two that I really need help with.

    First code:

    public class HEAPSTACK extends ConsoleProgram{
    public void run(){
    Integer n1=1;
    Integer n2=20;
    int computation=met h(n1,n2);
    println("comput ation:"+computa tion);

    Draw the heap-stack diagram when println has been called but before it runs}

    private int meth(int n2, int n1){
    Draw the heap-stack diagram when execution reaches this point return n2-n1;}}

    Second Code:

    public clas HEAPSTACK extends ConsoleProgram(
    public void run(){
    Rational a=new Rational(1,7);
    Rational b=new Rational(3,7);
    Rational c=a;
    Rational d=meth1(a,b);
    Draw the heap-stack diagram when execution reaches here}

    private Rational meth1(Rational x, Rational y){
    Rational z=x.add(y);
    return meth2(z);}
    private Rational meth2(Rational p){
    Rational a=new Rational (0,7);
    Draw the heap-stack diagram for when execution reaches here
    return (a.subtract(p)) ;
    }}
Working...