Я работаю над программой, которая делает правую и левую стрелки. Они расширены из класса ShapeBase, который реализуется из ShapeInterface. Я не вставлял их, чтобы он не выглядел подавляющим. Проблема в том, что я понял правильную стрелу (я верю), но не могу найти способ получить левую стрелку. Я все время смущаюсь и не могу понять, как это сделать. Любая помощь приветствуется. RightArrow Example OutputКак сделать левую стрелку звездочек в Java?
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(" ");
}
}
Благодарим вас за помощь. Я добавил класс ShapeBase к моему вопросу, если бы вы могли его повторить, я скорее не удалю большую часть своей работы. –
Существует много кода. Если вы видите код выше, как он работает, тогда вы сможете реализовать 'ArrowTail()' и 'bottomArrowHead()' методы ура. –
Хорошо, еще раз спасибо –