Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-06-2008, 10:57 AM
Member
 
Join Date: Feb 2008
Posts: 1
tiggz1980 is on a distinguished road
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.

import ou.*;

/**
* 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"
String asterisk;

/**
* Constructor for objects of class Triangle.
*/
public Triangle()
{
super();
this.size = 5;
this.orientation = "up";


}



/* instance methods */

/**
* Return the orientation of the triangle.
*/
public String getOrientation()
{
return this.orientation;
}

/**
* Return the size of the triangle.
*/
public int getSize()
{
return this.size;
}

/**
* Generates a row of Asterisks
*/
public String generateRow()
{
asterisk = "";
aSize = Integer.parseInt(return this.size);
for (int num = 1; num <= asize; num++)

asterisk = asterisk + "*";

System.out.prinln(asterisk);
}

}
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 02-06-2008, 11:39 AM
Member
 
Join Date: Dec 2007
Posts: 32
felixtfelix is on a distinguished road
Try the following piece of code. It will draw downwards. Make a try for the upward one also.
import java.io.*;

public class DrawTriangle
{
private int rows;


public int getInteger()throws IOException
{

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
return Integer.parseInt(br.readLine());
}

public void generateTriangle()
{
for(int i=1;i<=rows;i++)
{
String currentRow="";
for(int j=1;j<=i;j++)
{
currentRow = currentRow +"*";
}
System.out.println(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();
draw.getNoOfRows();
draw.generateTriangle();
}
}
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 02-07-2008, 12:14 AM
CaptainMorgan's Avatar
Moderator
 
Join Date: Dec 2007
Location: NewEngland, US
Posts: 840
CaptainMorgan will become famous soon enoughCaptainMorgan will become famous soon enough
Send a message via AIM to CaptainMorgan
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.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
to our beloved Java Forums!
(closes on September 4, 2008)
Want to voice your opinion on your IDE/Editor of choice?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
!
Got a little Capt'n in you? (drink responsibly)
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Array problem.. help needed please! SCS17 New To Java 3 03-06-2008 11:30 PM
Java assignment xtianah77 New To Java 1 02-18-2008 12:54 AM
for Assignment plz help assamhammad New To Java 1 11-06-2007 09:35 PM
java assignment, need help bad. carlos123 New To Java 1 11-06-2007 05:53 PM
Cannot solve the coding problem of my assignment elimmom New To Java 3 08-13-2007 12:33 PM


All times are GMT +3. The time now is 11:39 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org