5 Replies - 479 Views - Last Post: 06 December 2012 - 07:05 PM Rate Topic: -----

#1 darkleoco  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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  Icon User is offline

  • </luck>
  • member icon

Reputation: 293
  • View blog
  • 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?
Was This Post Helpful? 0
  • +
  • -

#3 darkleoco  Icon User is offline

  • New D.I.C Head

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

Re: Creating a rectangle with Closed Intervals.

Posted 06 December 2012 - 06:35 PM

View PostLuckless, 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.
Was This Post Helpful? 0
  • +
  • -

#4 Luckless  Icon User is offline

  • </luck>
  • member icon

Reputation: 293
  • View blog
  • 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?
Was This Post Helpful? 0
  • +
  • -

#5 darkleoco  Icon User is offline

  • New D.I.C Head

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

Re: Creating a rectangle with Closed Intervals.

Posted 06 December 2012 - 06:46 PM

View PostLuckless, 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.
Was This Post Helpful? 0
  • +
  • -

#6 Luckless  Icon User is offline

  • </luck>
  • member icon

Reputation: 293
  • View blog
  • 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
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1