Question: Use Java to program the following. 1. Your program must not use any recursion 2. You must only implement each of the methods in ArrowheadCurve.java
Use Java to program the following. 1. Your program must not use any recursion 2. You must only implement each of the methods in ArrowheadCurve.java that had TODO Comments.
This is what I have so far.
import edu.support.AnimatedTurtle; import edu.support.EndWorld; public class ArrowheadCurve { /** * Given the character, return the appropriate production for that character. * Implements the Sierpinski Arrowhead Curve refer to * https://en.wikipedia.org/wiki/L-system#Example_5:_Sierpinski_triangle * (make sure to scroll down to the part about the Sierpinski Arrowhead Curve). * * @param c the character to expand. * @return the appropriate production for the given character. */ public static String getProd(char c) { // TODO: replace with your implementation return ""; } // end getProd /** * Given the String representing the current generation, return a new * String that is the result of applying the getProd rules to each * character in the current generation. * @param curGen a String that is the current generation. * @return a new String that is the result of applying the * getProd rules to each character in the current generation. */ public static String nextGen(String curGen) { // TODO: replace with your implementation return ""; } // end nextGen /** * Draw the given current generation using the given turtle and amount * for forward steps. * * @param curGen a String representing the current generation. * @param t the turtle to use for drawing. * @param forwardSteps the amount of steps to move on a forward. */ public static void draw(String curGen, AnimatedTurtle t, int forwardSteps) { // TODO: replace with your implementation } // end draw /** * Given the initial generation, and number of reps, advance the initGen * numRep times. Then create an EndWorld and AnimatedTurtle and * draw the results using the given forwardSteps value. * * @param initGen the initial or starting String * @param numReps the number of times to run nextGen on initGen * @param forwardSteps the number of forward steps to use when drawing. */ public static void demo(String initGen, int numReps, int forwardSteps) { // TODO: replace with your implementation } // end demo public static void main(String[] args) { // for your own use (and the TAs when grading) } // end main } // end ArrowheadCurve The Answer should look like the triangles below.
heres Animated Turtle
import edu.gatech.mediacomp.ModelDisplay; import edu.gatech.mediacomp.Turtle; /** * A version of the Turtle class that slows it * down so that it can be seen creating drawings. * */ public class AnimatedTurtle extends Turtle { /** * The default value for the delay. */ public static final int DEFAULT_DELAY = 50; /** * The number of milliseconds to pause * each time the Turtle is drawn. */ private int drawDelay; /** * Creates a new AnimatedTurtle. */ public AnimatedTurtle(ModelDisplay m) { super(m); setDelay(DEFAULT_DELAY); } // end constructor /** * Sets the number of milliseconds to pause * each time the turtle is drawn. * @param ms the number of milliseconds to pause * each time the turtle is drawn. */ public void setDelay(int ms) { drawDelay = Math.max(ms, 0); } // end setDelay /** * Gets the number of milliseconds paused * each time the turtle is drawn. * * @return the number of milliseconds paused * each time the turtle is drawn. */ public int getDelay() { return drawDelay; } // end getDelay @Override public void updateDisplay() { super.updateDisplay(); try { Thread.sleep(drawDelay); } catch (InterruptedException e) { // do nothing } } // end updateDisplay } // end class AnimatedTurtle and this is EndWorld
import edu.gatech.mediacomp.World; import javax.swing.*; import java.awt.*; import java.lang.reflect.Field; import java.util.Hashtable; import java.util.List; /** * A version of the World class that ends the program * when the window is closed. * */ public class EndWorld extends World { /** * The most amount of time to pause in * between turtle drawing. */ private static final int SLOWEST = 100; /** * The slider. */ private JSlider slider; /** * Creates a World. */ public EndWorld() { initWorld(); } /** * Creates a World of the specified size. * @param width the width. * @param height the height. */ public EndWorld(int width, int height) { super(width, height); initWorld(); } /** * Helper method for setup and GUI (re)layout. */ private void initWorld() { JFrame frame = getFrame(); // kill program when JFrame closes frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // remove this world from the content pane frame.getContentPane().remove(this); // now use BorderLayout instead and // add this object back this time in the CENTER // and add thE slider GUI frame.getContentPane().setLayout(new BorderLayout()); frame.getContentPane().add(makeSliderGUI(), BorderLayout.NORTH); frame.getContentPane().add(this, BorderLayout.CENTER); frame.pack(); } /** * Returns the JFrame that the World is displayed in. * @return the JFrame that the World is displayed in. */ public JFrame getFrame() { // Using reflection so we don't need to modify // the original World code // based on code taken from // last access Feb 4, 2017 try { Field theFrame = null; // NOTE: originally I had getClass() instead of // World.class which does NOT work theFrame = World.class.getDeclaredField("frame"); theFrame.setAccessible(true); return (JFrame) theFrame.get(this); } catch (NoSuchFieldException e) { System.err.println("Frame field in World does not exist! Returning null"); } catch (IllegalAccessException e) { System.err.println("Could not access frame field of World, returning null"); } return null; // fail } // end getFrame() /** * Creates and returns the slider GUI. * @return the slider GUI. */ private JComponent makeSliderGUI() { Box b = new Box(BoxLayout.Y_AXIS); b.add(new JLabel("Turtle Speed", JLabel.CENTER)); slider = new JSlider(0, SLOWEST, AnimatedTurtle.DEFAULT_DELAY); slider.setMajorTickSpacing(SLOWEST / 10); slider.setSnapToTicks(true); slider.setPaintTicks(true); slider.setPaintLabels(true); slider.setInverted(true); Hashtable labels = new Hashtable(); labels.put(0, new JLabel("Fastest")); labels.put(SLOWEST, new JLabel("Slowest")); slider.setLabelTable(labels); slider.addChangeListener(evt -> { // first make sure we are done adjusting if (!slider.getValueIsAdjusting()) { List turtles = this.getTurtleList(); for (AnimatedTurtle t : turtles) { t.setDelay(slider.getValue()); } } }); b.add(slider); return b; } } // end class EndWorld /3S2 OA Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
