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