Results 1 to 3 of 3
  1. #1
    annna is offline Member
    Join Date
    Jan 2010
    Posts
    4
    Rep Power
    0

    Default 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.

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    8

    Default

    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.

  3. #3
    annna is offline Member
    Join Date
    Jan 2010
    Posts
    4
    Rep Power
    0

    Default

    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

  1. Need help with my tutorial
    By annna in forum New To Java
    Replies: 2
    Last Post: 02-05-2010, 03:00 PM
  2. JSF Tutorial
    By teststest in forum JavaServer Faces (JSF)
    Replies: 9
    Last Post: 11-15-2009, 05:31 AM
  3. tutorial
    By ayangupta in forum Threads and Synchronization
    Replies: 1
    Last Post: 03-01-2009, 06:38 PM
  4. tutorial help
    By yuriythebest in forum Java Applets
    Replies: 1
    Last Post: 11-12-2008, 04:34 PM
  5. RCP tutorial
    By javaplus in forum Advanced Java
    Replies: 1
    Last Post: 12-25-2007, 04:19 AM

Posting Permissions

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