# Thread: Tutorial help LAST QNS

1. Member Join Date
Jan 2010
Posts
4
Rep Power
0

## Tutorial help LAST QNS

The last qns is so confusing. Need help!

A rectangle can be defined by two points (p, q) and (r, s). In this question, we shall
assume that p not equals r and q not equals s.
(a) Define a class Rectangle with two points as properties. Use the Point class
defined in part 3. (below)
(b) Ensure that the two points have private access.
(c) Write a constructor Rectangle(Point a, Point b) that takes as argument two
point objects and creates a Rectangle object.

class Point
{
private int x;
private int y;
Point()
{
this(0,0);
}
Point(int x, int y)
{
this.setPoint(x,y);
}
void setPoint(int x, int y)
{
this.setPoint(x,y);
}
void print()
{
System.out.println("Point: ");
System.out.println(x);
System.out.println(y);
}
}

Can someone explain what they are asking for?
What I did,
there are two classes, class Rectangle and class UseRectangle.
Under
class Rectangle
{
private int a;
private int b;

Rectangle(Point a, Point b)
{
this(0,0)
}

then??

And how to make use of the Point class in part 3?
Last edited by annna; 01-27-2010 at 09:18 AM.  Reply With Quote

2. ## A rectangle can be defined by two points (p, q) and (r, s). In this question, we shall
assume that p not equals r and q not equals s.
(a) Define a class Rectangle with two points as properties. Use the Point class
defined in part 3. (below)
(b) Ensure that the two points have private access.
(c) Write a constructor Rectangle(Point a, Point b) that takes as argument two
point objects and creates a Rectangle object.

Java Code:
```// [i]Define a class Rectangle[/i]
class Rectangle {
// [i]with two points as properties[/i]
// [i]Use the Point class defined in part 3[/i]
// [i]Ensure that the two points have private access[/i]
// Member variable declarations with [i]private[/i] access
private Point a;
private Point b;

// [i]Write a constructor Rectangle(Point a, Point b) that[/i]
// [i]takes as argument two point objects[/i]
Rectangle(Point a, Point b) {
this.a = a;
this.b = b;
// [i]and creates a Rectangle object[/i]
// next step...
}
}```
Since
In this question, we shall assume that p not equals r and q not equals s.
we don't need to do any checking to make sure we can actually use the Points sent in to the constructor.  Reply With Quote

3. Member Join Date
Jan 2010
Posts
4
Rep Power
0

## This is the rest of the question

(d) Write a print method in class Rectangle to print out the two associated points.
Use the print method of the Point class.
(e) Write a main method to test your program. Your method should perform the
i. Declare two Point variables to reference two separate Point objects.
ii. Declare a Rectangle variable to reference a newly created Rectangle object
which uses the Point objects above as properties.
iii. Print the Rectangle object and verify the correctness of the associated points.
(f) Write a default constructor Rectangle() that initializes the rectangle object with
both points as (0,0). Verify the correctness by printing out the points of the
rectangle within the main method.

My code
class Rectangle
{
private Point a;
private Point b;

Rectangle()
{
this.a=0;
this.b=0;
}

Rectangle(Point a,Point b)
{
this.a=a;
this.b=b;
}

void print()
{
System.out.println("Point:");
System.out.println(a);
System.out.println(b);
}
}

class UseRectangle
{
public static void main(String[] args)
{
Point a=new Point();
Point b=new Point();
}
}

There are errors, I don't know what to add or do away with.  Reply With Quote

#### Posting Permissions

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