Results 1 to 2 of 2
  1. #1
    TicTacTevin is offline Member
    Join Date
    Sep 2013
    Rep Power

    Default Need help with this assignment

    Hey guys, I need help with this one question on my assignment. I don't get how to do it. Thanks
    Java Code:
    import java.awt.Rectangle ; 
    import java.util.Random ;
       Practice using getX, getY, getWidth and getHeight
    public class IntersectionTester
        public static void main(String[] args)
        Random random = new Random() ;
        Rectangle box1 = new Rectangle(2 * random.nextInt(50), 
                           2 * random.nextInt(50),
                           2 * random.nextInt(100),
                           2 * random.nextInt(100)) ;
        //Reminder: do not write or change code outside of the todo regions.
        //----------------------Start here. Do not remove this comment.
        // todo: 1. Make a second rectangle, called box2, so that the top left corner of box2 is in the center of box1, the width of box2 is half the width of box1, and the height of box2 is half the height of box1.
        // approximate lines of code required: 4
        //----------------------End here. Do not remove this comment.
        Rectangle box3 = box1.intersection(box2) ;
        System.out.println(box2.equals(box3)) ;
    I wrote this
    Java Code:
    Rectangle box2 = new Rectangle(box1.getX(),
    and I got this error
    Java Code: cannot find symbol
    symbol  :  constructor Rectangle(double,double,double,double)
    location :  class java.awt.Rectangle
              Rectangle box2 = new Rectangle(box1,get(),
    1 error
    Can someone please tell me what to do here. Thanks
    Last edited by TicTacTevin; 09-15-2013 at 07:05 AM.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Voorschoten, the Netherlands
    Blog Entries
    Rep Power

    Default Re: Need help with this assignment

    Read what the compiler message is trying to tell you: there is no constructor in the Rectangle class that takes four doubles for its parameters (also read the API documentation for the Rectangle class). You can cast the four values to ints '(int)value'.

    kind regards,

    Build a wall around Donald Trump; I'll pay for it.

Similar Threads

  1. Help with assignment
    By snobbysteven in forum New To Java
    Replies: 1
    Last Post: 10-20-2012, 06:24 AM
  2. What does this assignment do
    By lenaf7 in forum New To Java
    Replies: 4
    Last Post: 10-18-2012, 06:58 PM
  3. assignment help :L
    By Mike09lfc in forum New To Java
    Replies: 2
    Last Post: 12-03-2011, 02:38 AM
  4. Need help with a HW assignment
    By mackavelirip in forum New To Java
    Replies: 4
    Last Post: 02-17-2011, 01:36 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts