Given this client

/* Test of
 *    Constructor with 2 arguments
 *    drawLine
 *    setSize
 */

public class BoxesClient5
{
   public static void main(String[] args)
   {
      Boxes alphaBox;
      int i;
      
      System.out.println("Result of various calls to drawLine:");

      alphaBox = new Boxes(7, 'a');
      
      for ( i = 0; i < 5; i++ ) {
         alphaBox.setSize( alphaBox.getSize() + 1 );
         alphaBox.drawLine();
      }

      for ( i = 0; i < 5; i++ ) {
         alphaBox.setSize( alphaBox.getSize() - 1 );
         alphaBox.drawLine();
      }

   } // end of method main
} // end of class BoxesClient5

I need to write a class file to make it print something along the lines
+-----+ the number of dash's depends on the length that is used.

I have this so far:

public class Boxes{
	
	// instance variables
	
	private int size;
	private char symbol;
	
	// constructor
	
	public Boxes(int length, char FillChar){
		size = length;
		symbol = FillChar;
	}
	
	public Boxes(){
		size = 5;
		symbol = 'z';
	}
	
	public boolean equals(Boxes obj){
		if(size == obj.size && symbol == obj.symbol){
			return true;
		}
		else{
			return false;
		}
	}
	 
	// getter
	
	public char getFillChar(){
		return symbol;
	}
	public int getSize(){
		return size;
	}
	
	// setter
	
	public void setSize(int setSize){
		size = setSize;
	}
	
	public void setFillChar(char setFillChar){
		symbol = setFillChar;
	}
	
	// toString
	
	public String drawLine(){
		String line = "";
		for(int h = size; h>0; h--){
			line = line + "-";
		}
		return '+' + line + '+';
	}
	public String toString(){
		return "" + size 
		 + "\n" + symbol;
		}
	}

When I try to print the line, it just prints a blank space. Could you please tell me what I can change to fix this? I have to do this for an upward triangle, downward triangle and box as well, but I think I should be able to get those as long as I can get this one to print.

Thanks

Short of compiling and running your program for you, I think there are two things you could do to figure this out yourself:

1) Put in System.out.println() in the loop for drawLine() and see what is happening. And if you don't get it called, I'd put it outside the loop as well and find out what size is.

2) For the more adventurous, I'd setup the debugger in Eclipse or some similar IDE and step through the code one line at a time until I saw the problem. That's what makes a good programmer.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.