2016-03-31 5 views
-1

右矢印と左矢印を作るプログラムを作っています。これらは、ShapeInterfaceから実装されたShapeBaseクラスから拡張されています。圧倒されないように貼り付けなかった。問題は、私は右の矢を(私は信じている)考え出したが、左矢印を得るための自分の道を見つけることができないということです。私は混乱し続けるし、それを行う方法を理解していないようです。どんな助けもありがとうございます。左矢印CLASS FOR RightArrow Example OutputJavaでアスタリスクの左矢印を作成するにはどうすればよいですか?

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(" "); 
     } 
} 

答えて

0

知らない、(あなたが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(); 
    } 
} 
+0

ありがとうございました。私はShapeBaseクラスを私の質問に追加しました。あなたがもう一度それを見直すことができたら、私はすでに多くの仕事を消していません。 –

+0

多くのコードがあります。どのように動作するのか上のコードを見ると、あなたはurの独自メソッドArrowTail()とbottomArrowHead()を実装することができます。 –

+0

もう一度ありがとう –

関連する問題