Creating a rectangle with Closed Intervals.

Page 1 of 1

5 Replies - 1059 Views - Last Post: 06 December 2012 - 07:05 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=303032&amp;s=d0c0ab2100e8f958bc7dccd44bc3f93a&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

#1 darkleoco

Reputation: 0
• Posts: 3
• Joined: 06-December 12

Creating a rectangle with Closed Intervals.

Posted 06 December 2012 - 02:57 PM

1. A constructor that takes two ClosedInterval parameters and initializes the fi elds of the object as appro-
priate. The first parameter is the ClosedInterval object that represents the closed interval that is the
projection of the Rectangle onto the x-axis. The second parameter is the ClosedInterval object that
represents the closed interval that is the projection of the Rectangle onto the y-axis.

2. A constructor that takes four int parameters. The first two parameters are the left endpoint and
length of the corresponding ClosedInterval object for the x-axis. The last two parameters are the
bottom endpoint and the length of the corresponding ClosedInterval object for the y-axis.

```public Rectangle(ClosedInterval x, ClosedInterval y)
```

```public Rectangel(int a, int b, int c, int d)
```

Is that all that is needed for the first two steps? The terminology in step 1 as well as in the description of this project is more than a little confusing. I understand step 2 fine but I would just like to be sure as this project counts for a significant portion of my grade in CS 150.

Is This A Good Question/Topic? 0

Replies To: Creating a rectangle with Closed Intervals.

#2 Luckless

• </luck>

Reputation: 293
• Posts: 1,146
• Joined: 31-August 09

Re: Creating a rectangle with Closed Intervals.

Posted 06 December 2012 - 06:30 PM

Looks good to me. It seems you understand constructors pretty ok =) Is closed interval a class that is provided to you or do you have to write it yourself?

#3 darkleoco

Reputation: 0
• Posts: 3
• Joined: 06-December 12

Re: Creating a rectangle with Closed Intervals.

Posted 06 December 2012 - 06:35 PM

Luckless, on 06 December 2012 - 06:30 PM, said:

Looks good to me. It seems you understand constructors pretty ok =) Is closed interval a class that is provided to you or do you have to write it yourself?

It is provided to us but we can't view its source code so when we are required to call its methods we have to give our best guess on the specifics of it I talked to some students in my class and no one was able to view the source code of it.

One problem I have run into is.

3. A public method named contains that returns a boolean value and has two int parameters. The
parameters are the x- and y-coordinates of a position in the x/y plane. The method returns true if
that position is within the Rectangle; otherwise it returns false. You must implement this method
using the contains method of the ClosedInterval class

It wants the method to take two integer parameters however the ClosedInterval class's contains method only takes one integer parameter however so I am not quite sure where to go with that, whether I call it twice or if there is a problem with the ClosedInterval class provided to us.

#4 Luckless

• </luck>

Reputation: 293
• Posts: 1,146
• Joined: 31-August 09

Re: Creating a rectangle with Closed Intervals.

Posted 06 December 2012 - 06:41 PM

Can you post your rectangle class thus far so we can see what's being set up in your constructor? What does the ClosedInterval constructor look like and what other methods does it have?

#5 darkleoco

Reputation: 0
• Posts: 3
• Joined: 06-December 12

Re: Creating a rectangle with Closed Intervals.

Posted 06 December 2012 - 06:46 PM

Luckless, on 06 December 2012 - 06:41 PM, said:

Can you post your rectangle class thus far so we can see what's being set up in your constructor? What does the ClosedInterval constructor look like and what other methods does it have?

```public class Rectangle
{
private int x;

public Rectangle(ClosedInterval x, ClosedInterval y)
{

}
public Rectangle(int leftend, int leftlength, int bottomend, int bottomlength)
{

}
public void contains(int xcord, int ycord)
{
ClosedInterval.contains(xcord, ycord);
}
public String toString()
{

}
public boolean isSame(Rectangle check)
{

}
public void intersection(Rectangle intersect)
{

}
public void getXInterval()
{

}
public void getYInterval()
{

}

}

```

I would answer your question about the ClosedInterval constructor but it tells me it cannot open the source of that class, though it does have the needed methods my class said.

#6 Luckless

• </luck>

Reputation: 293
• Posts: 1,146
• Joined: 31-August 09

Re: Creating a rectangle with Closed Intervals.

Posted 06 December 2012 - 07:05 PM

Ok, look at this:

```class Rectangle{
ClosedInterval x, y;

public Rectangle(ClosedInterval x, ClosedInterval y){
this.x = x;
this.y = y;
}
public Rectangle(int leftend, int leftlength, int bottomend, int bottomlength){
this.x = new ClosedInterval(leftEnd, bottomEnd);
this.y = new ClosedInterval(leftLength, bottomLength);
}

//contains

}

```

I bet that this is what your ClosedInterval class constructor will look like. Now in your rectangle contains method, check if the int x is inside ClosedInterval x and do the same for y

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }