takes an integer argument and returns a string of asterisks; the number of asterisks in
the string is given by the value of the argument. Your method should use a loop and
concatenation to build up the row of asterisks. don’t forget to provide a brief initial
comment for your method.
Write a public instance method called toString() that takes no arguments. The
method should return a string made up by concatenating strings of asterisks (separated
by a newline character). If the instance variable orientation references the string
“up” the strings should be of ever increasing length from 1 up to the value of the
instance variable size. If the instance variable orientation references the string
“down” the strings should be of ever decreasing length from the value of the size
down to 1.
Hint: A newline character can be added to a string by concatenating it with the
expression System.getProperty(“line.separator”). For example:
“Hello” + System.getProperty(“line.separator”) + “World”
evaluates to the string:
“Hello
World”
Note that the method must return the string object it has constructed. It should not
output it either to a dialogue box or by using System.out.println(). You should
use a loop to construct the string that has to be returned; each iteration should involve
adding an extra row of asterisks to the string by using concatenation.
You can test that your new method works by creating a new instance of Triangle and
sending it a toString() message and observing the results in the Display Pane.
Sending toString() to a Triangle object which has a size of 5 and an orientation of
“up” should result in the following being shown in the Display Pane:
“*
**
***
****
*****
”
Note that the quote marks will be displayed. If, however, you execute code such as:
Triangle t;
t = new Triangle();
The textual representation of the triangle will be shown without quote marks:
*
**
***
****
*****
To test your method thoroughly, you should change the constructor before each test so
that it sets size and orientation to different values.





