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

(java) According to certain characters such as ; \'A\', \'B\',\'+\',\'-\'. How c

ID: 3829715 • Letter: #

Question

(java) According to certain characters such as ; 'A', 'B','+','-'. How can you implement the A and B to forward(); and + to turnLeft() and - to turnRight() ?

Once I have each character do a command I need to group them into a string called curGen. EX: "+B-A-B+" and have them do something like; turnLeft(),forward(),turnRight(),forward(),turnRight(),forward(),turnLeft()

* 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 implementation here

HOW CAN I FIX THIS? OR IS THIS CORRECT

curGen = "";
char a = 'A';
if(curGen=="A");
t.forward(50);
char b = 'B';
if(curGen=="B");
t.forward(50);
char left = '+';
if(curGen=="+");
t.turn(-60);
char right = '-';
if(curGen=="-");
t.turn(60);

Explanation / Answer

   public static void draw(String curGen, AnimatedTurtle t, int forwardSteps) {
//TODO implementation here
  
curGen = "+B-A-B+";

for(int i=0;i<curGen.length();i++)
{
   char a=curGen.charAt(i);
   if(a=='A'||a=='B')
   {
   t.forward(50);  
   }
   else if(a=='+')
   {
   //   t.turn(-60);
   t.turnLeft(-60);
      
   }
   else
   {
       t.turnRight(+60);
      
   }
}
}

//i have fix this i have taken each character one by one in for loop and analyse each character and according take //action