Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: help guys.. could you tell me what am i doing wrong?

  1. #1
    Junior Member
    Join Date
    Nov 2010
    Posts
    28
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default help guys.. could you tell me what am i doing wrong?

    i am designing this my circle class

    i. It should contain three private doubles for x, y and radius.
    ii. A constructor that accepts three double parameters for x, y, and radius.
    iii. A constructor that accepts a MyPoint and a radius. This constructor should
    call the constructor in ii.
    iv. A no-arg constructor that creates a circle at (0,0) with radius 1. This
    constructor should call the constructor in iii.
    v. Three get methods for the x, y and radius properties.
    vi. Three set methods for the x, y and radius properties.
    vii. A method named distance that returns the distance (a double) between this
    MyCircle and another MyCircle.
    viii. A method named contains that returns true if and only if the MyCircle
    contains a MyPoint passed as a parameter.
    ix. A method named contains that return true if and only if the MyCircle
    completely contains a MyCircle passed as a parameter.
    x. A toString method.
    xi. A static void main method for testing the MyCircle class


    so far i have this code

    public class MyCircle {
    private double x;
    private double y;
    private double radius;


    public MyCircle(double x, double y, double radius){
    this.x = x;
    this.y = y;
    this.radius = radius;
    }

    public MyCircle(MyPoint point, double rad){
    this.x = point.getX();
    this.y = point.getY();
    this.radius = rad;
    }

    public MyCircle(){
    this.x = 0;
    this.y = 0;
    this.radius = 0;
    }

    public double getX(){
    return x;
    }

    public double getY(){
    return y;
    }

    public double getRadius(){
    return radius;
    }

    public void setX(double x){
    this.x = x;
    }

    public void setY(double y){
    this.y = y;
    }

    public void setRadius(double radius){
    this.radius = radius;
    }

    public double distance(MyCircle other){
    double result = 0;

    double tmpX = this.x - other.x;
    double tmpY = this.y - other.y;

    result = Math.sqrt((tmpX*tmpX)*(tmpY*tmpY));


    return result;

    }

    public boolean contains(MyPoint o){
    boolean tmp;
    double result;

    double tmpX = this.x - o.getX();
    double tmpY = this.y - o.getY();
    System.out.println(tmpX);
    System.out.println(o.getX() + " + " + this.x);
    result = Math.sqrt((tmpX*tmpX)*(tmpY*tmpY));
    System.out.println(result);
    if(result < this.radius)
    tmp = true;
    else
    tmp = false;
    return tmp;

    }

    public String toString(){
    return "Point x = " + this.x + "\nPoint y = " +this.y
    + "\nRadius = " +this.radius;
    }



    public static void main(String [] args){

    MyPoint p = new MyPoint(1,4);
    MyCircle c = new MyCircle(p,3);
    System.out.println(c);
    MyCircle x = new MyCircle();
    boolean tmp = x.contains(p);
    System.out.println(tmp);

    }
    }


    and could someone explain the rule ix, thx god bless


  2. #2
    Junior Member
    Join Date
    Feb 2011
    Posts
    11
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default Re: help guys.. could you tell me what am i doing wrong?

    If A and B are circles. B is contained in A if and only if the distance between A and B plus the radius of B is smaller than radius of A.

    make sense? I think so.

Similar Threads

  1. Hi Guys
    By dazzl3r in forum Member Introductions
    Replies: 1
    Last Post: December 7th, 2010, 04:04 PM
  2. Hi guys
    By nextngema in forum Java SE APIs
    Replies: 2
    Last Post: July 17th, 2010, 04:34 PM
  3. hey guys....
    By prince joseph in forum Member Introductions
    Replies: 2
    Last Post: March 27th, 2010, 11:15 PM
  4. Hi guys
    By fembiz in forum Member Introductions
    Replies: 3
    Last Post: December 11th, 2009, 03:36 AM
  5. need help guys
    By Imeri0n in forum Java Theory & Questions
    Replies: 9
    Last Post: December 3rd, 2009, 09:39 AM