Question: Need to write two methods for MakeFractal.java and DrawFractal.java 1.You need to write a method buildFractal() for MakeFractal.java. This method uses a stack to perform
Need to write two methods for MakeFractal.java and DrawFractal.java
1.You need to write a method buildFractal() for MakeFractal.java. This method uses a stack to perform the iterations to build the final complex fractal string You process symbols (as Strings) left to right, symbols with production rules are replaced with those rules (and these symbols are pushed onto the stack) while other symbols are just pushed without substitution. At the end of iterations we pop the stack and concatenate it to the front (of an initially empty) string to represent the fractal.
2.You also need to write a method computeLines in the class DrawFractal.java that takes the string representing the fractal and produces an array of line objects that draw the fractal. A stack is needed to process the symbols "[" and "]" (push and pop) via a stack to handle branching.
import java.util.Arrays; public class MakeFractal { private final static int NOT_FOUND=-1; private String alphaNumeric; private String computedFractal; // the initial string is the axion private String initialAxion; // the initial string is the axion private Integer index,numSymbols,n,size; private String[] symbols; private String[] rules; private Integer charsPerLine=60; // constructor public MakeFractal(String[] symbols,Integer numSymbols, String initialAxion,String[] rules,Integer n) { this.numSymbols=numSymbols; this.symbols=new String[this.numSymbols]; this.rules=new String[this.numSymbols]; for(int i=0;i s = new LinkedStack(); ************************ **** YOUR CODE HERE **** ************************ return computedFractal; } // Return the index of the character in symbols // or -1 if it is not there public Integer in(String alphaNumeric,String[] symbols) { for(int i=0;i public class DrawFractal { private double x1=0.0; private double y1=0.0; private double drawingDir=0.0; private double length=1.0; private double angle; private double scalingFactor; private double x2,y2; private final static int DEFAULT = 1000; private LineInfo[] lines; private Integer lineCount=0; private CurrentPointInfo CP; private double Xmin=0.0; private double Xmax=0.0; private double Ymin=0.0; private double Ymax=0.0; private String symbol; private String fractalString; // constructor public DrawFractal(String fractalString,double scalingFactor,double angle) { this.fractalString=fractalString; this.scalingFactor=scalingFactor; this.angle=angle; } // Compute all lines of fractal public void computeLines() { angle*=Math.PI/180.0; // convert to radians // Array of line objects lines=new LineInfo[DEFAULT]; double mag; StackADT s = new LinkedStack(); ************************ **** YOUR CODE HERE **** ************************ } public void printAllLines() { int i=0; for(i=0;i Xmax) Xmax=x1; if(x2 > Xmax) Xmax=x2; if(y1 < Ymin) Ymin=y1; if(y2 < Ymin) Ymin=y2; if(y1 > Ymax) Ymax=y1; if(y2 > Ymax) Ymax=y2; } // Double the size of the lines array of type LineInfo public void expandCapacity() { LineInfo newLines[]= new LineInfo[lines.length*2]; for (int i=0;i < lines.length;i++) { newLines[i] = lines[i]; } lines=newLines; } } // DrawFractal
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
