如何用Java制作星号的左箭头?

时间:2016-03-31 10:53:24

标签: java extends shapes implements

我正在制作一个制作右箭头和左箭头的程序。它们是从ShapeBase类扩展而来的,该类是从ShapeInterface实现的。我没有粘贴它们所以它看起来不会让人不知所措。问题是我已经找到了右箭头(我相信)但找不到左箭头的方法。我一直感到困惑,似乎无法理解如何去做。任何帮助表示赞赏。 RightArrow Example Output

public abstract class ShapeBase implements ShapeInterface
{
private int offset;

public ShapeBase( )
{
    offset = 0;
}

public ShapeBase(int theOffset)
{
    offset = theOffset;
}

public abstract void drawHere( );

public void drawAt(int lineNumber)
{
    for (int count = 0; count < lineNumber; count++)
        System.out.println( );
    drawHere( );
}

public void setOffset(int newOffset)
{
    offset = newOffset;
}

public int getOffset( )
{
    return offset;
}
}





public class RightArrow extends ShapeBase
{
private int tail;
private int width;

public RightArrow()
{
    super();
    tail = 0;
    width = 0;
}

public RightArrow(int theOffset ,int tailSize, int theWidth)
{
    super(theOffset);
    tail = tailSize;
    width = theWidth;
    set(tail , width);
}
public void set(int newHeight, int newWidth)
{
    tail = newHeight;
    width = newWidth;
}

public void drawHere()
{
    topArrowhead();
    ArrowTail();
    bottomArrowHead();
}
public void topArrowhead()
{
    skipSpaces(getOffset());
    System.out.println("*");

    for(int i = 0; i<width/2; i++)
    {
        skipSpaces(getOffset());
        System.out.print("*");
        skipSpaces(i);
        System.out.println("*");
    }
}

// method to draw the arrow tail
public void ArrowTail()
{
    for(int count=0; count<tail; count++)
    {
        System.out.print("*");
    }
    skipSpaces(tail+width);
    System.out.print("*");

}

// method to draw bottom of arrowhead
public void bottomArrowHead()
{
    for(int i =1;i<width/2; i--)
    {
        skipSpaces(getOffset());
        System.out.print("*");
        skipSpaces(i);
        System.out.println("*");
    }
    skipSpaces(getOffset());
    System.out.println("*");
}

private static void skipSpaces(int number)
{
    for (int count=0; count< number; count++)
    System.out.print(" ");
}
}

对于左箭头类,我相信这些是唯一需要改变的方法。 我只是不知道如何

    public void topArrowhead()
        {
            skipsSpaces(getOffset());
            System.out.println("*");

            for(int i = 0 i<width/2; i++)
            {
                skipSpaces(getOffset());
                System.out.print("*");
                skipSpaces(i);
                System.out.println("*");
            }
        }

        // method to draw the arrow tail
        public void ArrowTail()
        {

        }

        // method to draw bottom of arrowhead
        public void bottomArrowHead()
        {

        }

        private static void skipSpaces(int number)
        {
            for (int count=0; count< number; count--)
            System.out.print(" ");
        }
}

1 个答案:

答案 0 :(得分:0)

这是你可以绘制左箭头的方法,它没有使用你的方法(因为你没有提供std::extent的来源)但你可以看到下面的实现如何创建它然后可以使用以你自己的方式。

ShapeBase