Results 1 to 3 of 3
Thread: Tutorial help LAST QNS
- 01-27-2010, 10:12 AM #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 10:18 AM.
- 01-27-2010, 04:41 PM #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... } }
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.
- 01-28-2010, 01:22 PM #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
following tasks:
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.
Similar Threads
-
Need help with my tutorial
By annna in forum New To JavaReplies: 2Last Post: 02-05-2010, 04:00 PM -
JSF Tutorial
By teststest in forum JavaServer Faces (JSF)Replies: 9Last Post: 11-15-2009, 06:31 AM -
tutorial
By ayangupta in forum Threads and SynchronizationReplies: 1Last Post: 03-01-2009, 07:38 PM -
tutorial help
By yuriythebest in forum Java AppletsReplies: 1Last Post: 11-12-2008, 05:34 PM -
RCP tutorial
By javaplus in forum Advanced JavaReplies: 1Last Post: 12-25-2007, 05:19 AM
Bookmarks