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

Hi, I would like to get help in designing a method that draws an arrow that poin

ID: 3534644 • Letter: H

Question

Hi, I would like to get help in designing a method that draws an arrow that point to the right like this:

*

* *

* *

* * * * * * * * * * *

* *

* *

*


and another method that draws the arrow pointitng LEFT.


I have thought about designing two methods: one for the tail, and one for the triangular head. The tail method is very simple. I'm just having trouble designing a method that draws the triangles. Here is my tail method:

public void drawTail(){

int tail = 8;

for(int i=0; i<tail; i++){

System.out.print("*");

}

System.out.println();

}

Explanation / Answer

With reverse Arrow added



class myjavaprg{
public static void main(String args[])
{
drawArrow();
drawArrowReverse();
}

public static void drawTail(){
int tail = 8;
for(int i=0; i<tail; i++){
System.out.print("*");
}
}

public static void drawArrow()
{
for(int i = 0 ; i<7 ; i ++)
{
if( i == 3)
{
drawTail();
//Drawing the pointed Tip
for (int j = 0 ; j < 3;j++)
{
System.out.print(" ");
}
System.out.println("*");

}else
{
//This is to draw the arrow
//Pad to the eigth position and draw a *
for (int j = 0 ; j < 7;j++)
{
System.out.print(" ");
}
System.out.print("*");

// If it is above the tail draw a Reversed V pattern else draw a v pattern
if( i < 4)
{
for (int k = 0 ; k < i;k++)
{
System.out.print(" ");
}
System.out.println("*");

}else
{

//Why start from six because we have 7 lines and maximum index that can be reached is six
for (int k = 6 ; k > i;k--)
{
System.out.print(" ");
}
System.out.println("*");

}
}

}
}


public static void drawArrowReverse()
{
for(int i = 0 ; i<7 ; i ++)
{
if( i == 3)
{
System.out.print("*");
//Drawing the pointed Tip
for (int j = 0 ; j < 3;j++)
{
System.out.print(" ");
}

drawTail();
System.out.println();

}else
{

if( i < 4)
{
for (int k = 3 ; k > i;k--)
{
System.out.print(" ");
}
System.out.print("*");
for (int k = 4 ; k > 4 - i ;k--)
{
System.out.print(" ");
}
System.out.println("*");

}else
{
for (int k = 4 ; k > 7-i;k--)
{
System.out.print(" ");
}
System.out.print("*");
for (int k = 0 ; k < 6-i;k++)
{
System.out.print(" ");
}
System.out.println("*");

}

}

}
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote