Total members 11892 |It is currently Sun Sep 22, 2024 2:42 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





Drawing rectangle using stars * in java
Here is a sample image.

Quote:
^
20+
|
|
|
|
15+
|
|
|
|
10+
|
|
|
|
5+
|
|
|
|
+----+----+----+----+----+----+----+----+>
0 5 10 15 20 25 30 35 40

Upper Left: (5,10) Width: 8, Height: 4

********
********
********


EDIT: noticed the horizontal and vertical numbers are off on the forum here, but fine in program console.


Here is the code.

Code:
/program START


//create class for filename
public class DrawRectangle 

{
   
    //create main arugment to show string text
    public static void main(String[] args)
       
    {
       
       
     
        //temporarly hard code values.
        int height = 4;
        int width = 8;
        int x = 5;
        int y = 10;


    //draw the whole graph and rectangle
        System.out.println("\n\n   ^");
       
        //draw the verticle axis
        for (int m = 20; m > 0; m--)
           
        {
      
   if (m == 5)
     System.out.println("  " + m + "+");
   
         else if (m % 5 == 0) 
            System.out.println(m + "+");
    
        else
            System.out.println("    |");
       
        }
       
   
        System.out.print("    ");
   
        //draw the horizontal axis
        for (int n = 0; n <= 40; n++)
           
        {
           if (n % 5 == 0)
           
               System.out.print("+");
               
           else
                System.out.print("-");
        }
       
        System.out.print(">");
       
        System.out.println();
       
        //create numbers for the horizontal axis
          for (int p = 0; p <= 40; p++)
           
        {
           if (p % 5 == 0)
           
               System.out.print("    " + p);
        }
       
       
        //draw the description
        System.out.println("\n\n Upper Left: (" + x + ","  + y + ") Width: " + width + ", Height: " + height + "\n\n");
       
 
      
   [color=#FF0000]//printing the rectangle
   for (int hcount = 1; hcount <= height; hcount++)
           
   {
      System.out.println("");
       
      for(int wcount = 1; wcount <= width; wcount++)
           
      System.out.print("*");
   }[/color]
     
       
    } // main method end brace.
   
} // drawrectangle class end brace

//program END





So what is my problem?

Well I need the "*" rectangle to fit on the graph, on the PROPER coordinates.

Basically, I just need a starting point for the code highlighted in red to execute.

Now I just can't seem to figure it out.

I'm wondering... if x = n (the horizontal axis) and if y = m (the vertical axis). Then I'd assume the rectangle would execute at the correct coordinates?

I'm just a bit blank on how to execute the rectangle loop.




Author:
Newbie
User avatar Posts: 1
Have thanks: 0 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : Drawing rectangle using stars in java
 Java Rectangle Class     -  
 Triangle of stars (C++)     -  
 Add voting by stars images to your website content     -  
 Ellipse in Rectangle     -  
 How to Calculate Volume of a Rectangle     -  
 Draw Fill Rectangle     -  
 Draw rectangle on image     -  
 ellipse, circle, rectangle, square, or parallelogram     -  
 Draw Oval,Arc,Polygon,string,Line,Round and 3D Rectangle     -  
 Drawing a Triangler in php     -  









Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com