Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Let\'s say our sequence starts off: 0,01,0110,01101001 b) Based on this sequence

ID: 3818625 • Letter: L

Question

Let's say our sequence starts off: 0,01,0110,01101001

b) Based on this sequence create the following graph. Starting from (0, 0), move one unit in the direction that you are facing if you encounter 1 in your sequence, and rotate by an angle of -pi/3 if you encounter 0 in your sequence. Write a method that produces this graph for the n-element in this sequence. Write a short client program that presents a graphic picture of it while reading from the terminal the required n (you are welcome to use scaling of the length of the step for large n).

Explanation / Answer

import scanner.*;

class MyGraph

{

//static int constant rotation_unit=60;

//static int constant rotation_constant=-60;

int rotate_by;

public static void main (String args[]) throws IOException

{

MyGraph mg= new MyGraph();

System.out.println("Enter the trigger to rotate in the form of 0 or 1");

int dir=Integer.parseInt(System.in());

mg.rotate(dir);

}

public void rotate(int dir)

{

int dir=dir;

int value=value;

if (value==1)

{

rotate_by=60;

System.out.println("Rotation by one unit that is 60 degree");

}

elseif(value==0)

rotate_by=-60;

System.out.println("Rotation by - 60 degree");

}

}