Results 1 to 14 of 14
Like Tree1Likes
  • 1 Post By gimbal2

Thread: Help with the class!

  1. #1
    hawk-dc is offline Member
    Join Date
    Nov 2013
    Posts
    22
    Rep Power
    0

    Default Help with the class!

    Hi.. why am I not getting a proper shape of "Leftarrow"? The result should look like the following (the system draws the arrow abnormally, so the beginning should a real ARROW:
    *
    * *
    * *
    * * * * * * * * *
    * *
    * *
    *

    Thanks in advance!

    here is the class:

    Java Code:
    public class LeftArrow extends ShapeBase  {
    	
    	
    	private int lengthOfTail;
    	private int widthOfArrowHead;
    	
    	public LeftArrow()
    	{
    		super();
    		lengthOfTail = 0;
    		widthOfArrowHead = 0;
    	}
    	public LeftArrow (int newOffset, int newLength, int newWidth)
    	{
    		super(newOffset);
    		
    		lengthOfTail = newLength;
    		if(newWidth % 2 != 0)
    			widthOfArrowHead = newWidth;
    		else
    			widthOfArrowHead = newWidth + 1;
    	}
    	public void indent()
    	{
    		int offset = getOffset();
    		for (int i = 1; i <= 1; i++)
    			System.out.print(' ');
    	}
    	public void printSpaces()
    	{
    		for(int i = 1; i < lengthOfTail; i++)
    			System.out.print(' ');
    	}
    	public void printStars()
    	{
    		for (int i = 1; i < lengthOfTail; i++)
    			System.out.println('*');
    	}
    	public void drawHere()
    	{
    		for (int line = 0; line < widthOfArrowHead; line++)
    		{
    			indent ( );
    			int middleLine = widthOfArrowHead/2; 
    			int actualLine = line;
    			
    			if (actualLine != 0)
    			{
    				for (int i =1; i <= actualLine; i++)
    					System.out.print(' ');
    				System.out.println('*');
    					
    			}
    			else 
    				System.out.println();
    			
    			if(line > middleLine)
    				actualLine = widthOfArrowHead - 1 - line;
    			if (actualLine != middleLine)
    				printSpaces();
    			else 
    				printStars();
    			System.out.print('*');
    	}
    	}
    Last edited by hawk-dc; 04-22-2014 at 04:14 AM.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,889
    Rep Power
    25

    Default Re: Help with the class!

    Look at the desired output line by line starting at the top.
    What goes on the first line column by column?
    Then the second line
    etc

    Now work on code to produce those lines.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    hawk-dc is offline Member
    Join Date
    Nov 2013
    Posts
    22
    Rep Power
    0

    Default Re: Help with the class!

    That's where I'm finding myself in trouble. I understand the algorithm but have difficulties with the code itself. Could you please put me on the right track regarding the code?

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,889
    Rep Power
    25

    Default Re: Help with the class!

    Ok, if you have the algorithm, post that so we can work on the code to do what the algorithm says to do.
    By algorithm, I mean the detailed steps the code needs to do to solve the problem.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    hawk-dc is offline Member
    Join Date
    Nov 2013
    Posts
    22
    Rep Power
    0

    Default Re: Help with the class!

    for the LeftArrow, for its start:
    1) draw one '*',
    2)then draw two vertical '*' separated by one empty line... and so on
    the desired result should be:
    O
    O O
    O OOOOOOO (instead 'O' there should be '*' though
    O O
    O

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,889
    Rep Power
    25

    Default Re: Help with the class!

    Java Code:
         *
       * *
     *   *
    *    * * * * * * * *
     *   * 
       * * 
          *
    1) draw one '*' ??? No leading spaces before the '*'?
    2)then draw two vertical '*' ??? On what lines and in what columns?
    and so on ??? That is really hard to write code for. Not specific enough. No way to write code for that design.

    There should be details for what is printed on each line, column by column

    I'm finished for tonight. I'll return tomorrow.
    Last edited by Norm; 04-22-2014 at 04:47 AM.
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    hawk-dc is offline Member
    Join Date
    Nov 2013
    Posts
    22
    Rep Power
    0

    Default Re: Help with the class!

    Here I've attached the picture of that
    Attached Thumbnails Attached Thumbnails Help with the class!-20140421_214945.jpg  

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,889
    Rep Power
    25

    Default Re: Help with the class!

    Now in words.
    What goes on first line?
    What goes on second line?
    etc
    what goes on last line?

    Is there a pattern? Can the logic for some of the lines be reused or is the line unique and must have special code to create it: like the shaft on the middle line?
    If you don't understand my response, don't ignore it, ask a question.

  9. #9
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,086
    Rep Power
    4

    Default Re: Help with the class!

    Quote Originally Posted by hawk-dc View Post
    for the LeftArrow, for its start:
    2)then draw two vertical '*' separated by one empty line... and so on
    You sure you don't mean horizontal?
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  10. #10
    hawk-dc is offline Member
    Join Date
    Nov 2013
    Posts
    22
    Rep Power
    0

    Default Re: Help with the class!

    Here's the RightArrow class which works properly:
    Java Code:
    public class RightArrow extends ShapeBase{
    	
    
    
    	
    	private int lengthOfTail;
    	private int widthOfArrowHead;
    	
    	public RightArrow()
    	{
    		super();
    		lengthOfTail = 0;
    		widthOfArrowHead = 0;
    	}
    	
    	
    	
    	public RightArrow(int newOffset, int newLength, int newWidth)
    	{
    		super(newOffset);
    		
    		lengthOfTail = newLength;
    		if(newWidth % 2 != 0)
    			widthOfArrowHead = newWidth;
    		else 
    			widthOfArrowHead = newWidth + 1;
    		
    	}
    	
    	public void indent ( )
    	{	int offset = getOffset ( );
    		for (int i = 1; i <= offset;i++)
    			System.out.print (' ');
    	}
    	
    	public void printSpaces ( )
    	{
    		for (int i = 1; i < lengthOfTail; i++)
    			System.out.print(' ');
    	}
    	
    	public void printStars ( )
    	{
    		for (int i = 1; i < lengthOfTail; i++)
    			System.out.print('*');
    	}
    	
    	
    	public void drawHere ( )
    	{
    		for (int line = 0; line < widthOfArrowHead; line++)
    		{
    			indent ( );
    			
    			int middleLine = widthOfArrowHead/2;
    			int actualLine = line;
    			if (line > middleLine)
    				actualLine = widthOfArrowHead - 1 - line;
    			
    			if (actualLine != middleLine)
    				printSpaces ( );
    			else
    				printStars ( );
    			System.out.print('*');
    			
    			if (actualLine != 0)
    			{
    				for (int i = 1; i <= actualLine; i++)
    					System.out.print (' ');
    				System.out.println ('*');
    			}
    			else
    				System.out.println ( );
    			
    			
    				
    			
    			
    		}
    	
    	}
    }

  11. #11
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,889
    Rep Power
    25

    Default Re: Help with the class!

    Have you solved the problem now?
    If you don't understand my response, don't ignore it, ask a question.

  12. #12
    hawk-dc is offline Member
    Join Date
    Nov 2013
    Posts
    22
    Rep Power
    0

    Default Re: Help with the class!

    Yeah, I did it !

  13. #13
    hawk-dc is offline Member
    Join Date
    Nov 2013
    Posts
    22
    Rep Power
    0

    Default Re: Help with the class!

    Sir, can you please refer me to any helpful website where I could keep practicing Java projects ?

  14. #14
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,354
    Rep Power
    6

    Default Re: Help with the class!

    There is no such thing; that is something you do yourself. Pick a doable project you would want to do and are willing to finish and then go do it. Don't hesitate to spend some time thinking about which project exactly. Just don't try to do something unique, it is in your interest to copycat something existing so you have an idea what it should look like and how it should functionally work.
    hawk-dc likes this.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Replies: 3
    Last Post: 12-08-2013, 10:28 PM
  2. Replies: 1
    Last Post: 12-13-2012, 04:06 AM
  3. Replies: 1
    Last Post: 11-29-2012, 10:46 AM
  4. Replies: 0
    Last Post: 03-27-2011, 06:49 AM
  5. Replies: 5
    Last Post: 01-26-2011, 07:38 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •