Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / December 2004

Tip: Looking for answers? Try searching our database.

help with asterisks

Thread view: 
Jo Campbell - 08 Dec 2004 00:27 GMT
This assignment  is really to learn about inheritance.  I have a main that
uses this program via inheritance, but I can't figure out how to make it
print the asterisks in the form of a triangle instead of a square.   Can
someone help me?

Thanks
Jo

public class Triangle extends Shape

{

      private int side;

            public Triangle()

           {

                 side = 0;

            }

            public Triangle(int sideLength, int offSet)

            {

                 super(offSet);

                 side = sideLength;

            }

            public String Draw()

            {

                 String out = "";

                     for (int i = 1; i <= side; i++)

                     {

                         out += super.Draw();

                                for (int j = 1; j <= side; j++ )

                               {
                                       out += "*     ";

                                }

                                       out += "\n";

                      }

               return out;

    }

        public String Display()

        {

             String out = "Triangle: side = " + side + " ";

             out += super.Display();

             return out;

        }

}
KC Wong - 08 Dec 2004 00:55 GMT
> This assignment  is really to learn about inheritance.  I have a main that
> uses this program via inheritance, but I can't figure out how to make it
> print the asterisks in the form of a triangle instead of a square.   Can
> someone help me?

Draw a triangle with asterisk on paper.

1           *
2          ***
3         *****

Then look at it line by line - observe the relationship between the line
numbers and the number of asterisks.
Next observe not only the asterisks, but also the space in front of
asterisks in each line too.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.