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: OOP composition - MyPoint and MyTriangle. need hint for building MyTriangle class

  1. #1
    Junior Member
    Join Date
    Mar 2014
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default OOP composition - MyPoint and MyTriangle. need hint for building MyTriangle class

    Basically i need to build this MyTriangle class. together with the code from MyPoint, i need to test out the following.

    oop.jpg
    when i try to build the constructor part where v1 = (x1, y1) it says my y1 is not a int variable.
    also how do i link the two class together?

    MyPoint code is as followed:

    public class MyPoint {
     
    	private int x;
    	private int y; 
     
    	public MyPoint(){
    		x = 0; 
    		y = 0; 
     
    	}public MyPoint(int x, int y){
    		this.x = x; 
    		this.y = y; 
     
    	}public int getX(){
    		return x; 
     
    	}public void setX(int x){
    		this.x = x; 
     
    	}public int getY(){
    		return y; 
     
    	}public void setY(int y){
    		this.y = y; 
     
    	}public void setXY(int x, int y){
    		this.x = x; 
    		this.y = y; 
     
    	}public String toString(){
    		return "(" + x + ", " + y + ")"; 
     
    	}public double distance(int x, int y){
    		int xDiff = this.x - x; 
    		int yDiff = this.y - y; 
    		return Math.sqrt(xDiff*xDiff + yDiff*yDiff); 
     
    	}public double distance(MyPoint another){
    		int xDiff = this.x - another.x; 
    		int yDiff = this.y - another.y;
    		return Math.sqrt(xDiff*xDiff + yDiff*yDiff); 
     
    	}
    }


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: OOP composition - MyPoint and MyTriangle. need hint for building MyTriangle class

    I don't see a v1, x1, or y1 in the code you posted. Please post the code producing the error AND the entire error message/stack trace, copied from exactly as it appears at your end and pasted into your post.

Similar Threads

  1. Replies: 2
    Last Post: September 5th, 2013, 03:43 AM
  2. Am I demonstrating composition correctly?
    By orbin in forum What's Wrong With My Code?
    Replies: 0
    Last Post: August 2nd, 2012, 10:40 PM
  3. Building your own Date class.
    By ShaunB in forum Java SE API Tutorials
    Replies: 5
    Last Post: October 25th, 2011, 05:37 PM
  4. Building your own Date class.
    By ShaunB in forum Java Code Snippets and Tutorials
    Replies: 1
    Last Post: May 21st, 2011, 06:11 PM
  5. new Vs composition
    By mos33 in forum Object Oriented Programming
    Replies: 2
    Last Post: November 16th, 2009, 01:53 PM