[英]How do I make a left arrow of asterisks in Java?
I'am working on a program that makes right and left arrows.我正在开发一个制作左右箭头的程序。 They are extended from a ShapeBase class which is implemented from a ShapeInterface.
它们是从从 ShapeInterface 实现的 ShapeBase 类扩展而来的。 I didn't paste them so it wouldn't look overwhelming.
我没有粘贴它们,所以它看起来不会让人不知所措。 The problem is I have figured out the right arrow ( I believe) but cannot find my way to getting the left arrow.
问题是我已经找到了右箭头(我相信),但找不到获得左箭头的方法。 I keep getting confused and cant seem to understand how to do it.
我一直感到困惑,似乎无法理解如何去做。 Any help is appreciated.
任何帮助表示赞赏。 RightArrow Example Output
RightArrow 示例输出
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(" ");
}
}
FOR THE LEFT ARROW CLASS, I believe these are the only methods need changing.对于左箭头类,我相信这些是唯一需要改变的方法。 I just don't know how
我只是不知道如何
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(" ");
}
}
This is how you can draw a left arrow,it doesn't uses your methods(as you not provided source for ShapeBase
) but you can see the implementation below how its get created and then can use in your own way.这是您绘制左箭头的方式,它不使用您的方法(因为您没有为
ShapeBase
提供源),但您可以在下面看到它是如何创建的,然后可以以您自己的方式使用。
public class LeftArrow
{
private int tail=15;
private int width=7;
//Method to draw the left arrow
public void DrawArrow()
{
for(int i = 0,r=0; i<width; i++)
{
//for spaces before head
for(int j=0;j<(width/2)-r;j++)
System.out.print(" ");
for(int j=0;j<=r;j++)
{
if(j==r || j==0)
System.out.print("*");
else
System.out.print(" ");//for spaces inside head
}
if(i==width/2)//to draw tail after the mid of head
ArrowTail();
if(i<width/2)//controls the increment & decrements of spaces before head
r++;
else r--;
System.out.println();
}
}
// method to draw the arrow tail
public void ArrowTail()
{
for(int count=0; count<tail; count++)
{
System.out.print("*");
}
}
public static void main(String[] args)
{
LeftArrow Arrow = new LeftArrow();
Arrow.DrawArrow();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.