Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: grow a rectangle in java

  1. #1
    Junior Member
    Join Date
    Sep 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default grow a rectangle in java

    Write a program called RectangleFive. It should have a method which, when called on an arbitrary rectangle (not just square), will make the length of each rectangle side grow to be 5 times as large, while keeping its original location (upper left corner) the same.
    import java.awt.Rectangle;
     
    public class RectangleFive
    {
    public static void main(String[] args)
    {
    Rectangle box = new Rectangle(5, 10, 20, 30);
    RectangleFive.quintupleRectangle(box);
    //Don't worry about the above syntax
     
    System.out.println(box.getX());
    System.out.println("Expected 5");
    System.out.println(box.getY());
    System.out.println("Expected 10");
    System.out.println(box.getWidth());
    System.out.println("Expected 100");
    System.out.println(box.getHeight());
    System.out.println("Expected 150");
    }
     
    public static void quintupleRectangle(Rectangle box)
    {
    int width = (int) box.getWidth();
    int height = (int) box.getHeight();
    //Don't worry about the (int) above, we haven't learned that syntax yet
     
    //Your work goes here
    }
     
    }
    Hint: Draw a picture, and read the API.
    Last edited by copeg; September 8th, 2010 at 06:01 PM. Reason: Please use the highlight tags


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: grow a rectangle in java

    What exactly is your question? No one is going to do your homework for you, but if you have a particular question we will help out as best we could. For what its worth...read the API for Rectangle (Java Platform SE 6)

  3. #3
    Junior Member
    Join Date
    Sep 2010
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: grow a rectangle in java

    box.setBounds(5, 10, 5 * width, 5 * height);

Similar Threads

  1. How to form a rectangle from the union of two Rectangles.
    By javapenguin in forum What's Wrong With My Code?
    Replies: 8
    Last Post: September 3rd, 2010, 07:22 AM
  2. Fill in rectangle partially (clip?¿)
    By OBLITERATOR in forum AWT / Java Swing
    Replies: 5
    Last Post: March 27th, 2010, 01:38 PM
  3. here to learn and grow
    By cejay in forum Member Introductions
    Replies: 2
    Last Post: March 1st, 2010, 03:04 AM
  4. centering a label inside a rectangle
    By Brain_Child in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 19th, 2009, 09:08 AM
  5. Dropping to graphic element dragged from JList
    By tua1 in forum AWT / Java Swing
    Replies: 1
    Last Post: November 29th, 2008, 08:22 AM