Results 1 to 3 of 3
Thread: assignment problem help needed
- 02-06-2008, 09:57 AM #1Member
- Join Date
- Feb 2008
- Rep Power
assignment problem help needed
Hi all i am currently doing an assignment and struggling like mad all i need to do is create a right angled triangle out of asterisks such as
it has the size set to 5 and the orientation set to up all i need to know is how to get the public instance method called generate row to work correctly any help would be appreciated i am drowning i cannot get to grips with this at all.
the code for the method is below it should use a loop and concatenation to produce the triangle any help on this would be grateful.
* Class Triangle - instances model triangles as rows of asterisks
* M255 Course Team
* Version 1.0
public class Triangle
/* instance variables */
int size; // the size of the triangle; an integer between 2 and 10 inclusive
String orientation; // either "up" or "down"
* Constructor for objects of class Triangle.
this.size = 5;
this.orientation = "up";
/* instance methods */
* Return the orientation of the triangle.
public String getOrientation()
* Return the size of the triangle.
public int getSize()
* Generates a row of Asterisks
public String generateRow()
asterisk = "";
aSize = Integer.parseInt(return this.size);
for (int num = 1; num <= asize; num++)
asterisk = asterisk + "*";
- 02-06-2008, 10:39 AM #2Member
- Join Date
- Dec 2007
- Mumbai, India
- Rep Power
Try the following piece of code. It will draw downwards. Make a try for the upward one also.
public class DrawTriangle
private int rows;
public int getInteger()throws IOException
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public void generateTriangle()
currentRow = currentRow +"*";
public void getNoOfRows()throws IOException
System.out.print("Enter no of rows:");
rows = getInteger();
public static void main(String args)throws IOException
DrawTriangle draw = new DrawTriangle();
- 02-06-2008, 11:14 PM #3
First welcome to the Java Forums!
Second, it seems you're going to too much trouble to get the program functioning as it should. There's a recent Triangle question in the forums, see if that helps.
- By SCS17 in forum New To JavaReplies: 3Last Post: 03-06-2008, 10:30 PM
- By xtianah77 in forum New To JavaReplies: 1Last Post: 02-17-2008, 11:54 PM
- By assamhammad in forum New To JavaReplies: 1Last Post: 11-06-2007, 08:35 PM
- By carlos123 in forum New To JavaReplies: 1Last Post: 11-06-2007, 04:53 PM
- By elimmom in forum New To JavaReplies: 3Last Post: 08-13-2007, 11:33 AM