ScholarMatic | 24/7 Homework Help

ScholarMatic Will Help You Write Your Essays and Term Papers

Answered » You can buy a ready-made answer or pick a professional tutor to order an original one.

Java Triangle Program using generateRow()

by | Nov 29, 2023 | questions

1:Write a public instance method called generateRow() for the Triangle class that
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.

ScholarMatic: Explanation & Answer

Your ready answer from a verified tutor is just a click away for as little as $14.99


  

Click Order Now to get 100% Original Answer Customized to your instructions!

HOME TO CERTIFIED WRITERS

Why Place An Order With Us?

  • Certified Editors
  • 24/7 Customer Support
  • Profesional Research
  • Easy to Use System Interface
  • Student Friendly Pricing

Have a similar question?

PLAGIRAISM FREE PAPERS

All papers we provide are well-researched, properly formatted and cited.

TOP QUALITY

All papers we provide are well-researched, properly formatted and cited.

HIGHLY SECURED

All papers we provide are well-researched, properly formatted and cited.

ScholarMatic: Get Started

Assignment Writing Service

Feel safe and secure when placing an order on our portal!
Fruitful cooperation begins with solid guarantees, and we are professional enough to promise perfect results. Let’s get it started!