Results 1 to 6 of 6
  1. #1
    Omgium is offline Member
    Join Date
    Dec 2012
    Posts
    3
    Rep Power
    0

    Default using classes help

    Hi, I am struggling trying to figure out what i'm doing wrong. I am having trouble understanding some online tutorials and was hoping someone coud explain what I'm doing wrong here.
    example of what I'm doing

    class I'm working with:
    Java Code:
    public class Point {
    	private int x;
    	private int y;
    	
    	public Point(){
    		this.x = 0;
    		this.y = 0;
    	}
    	public Point(int initialX, int initialY){
    		this.x = initialX;
    		this.y = initialY;
    	}
    	public void Translate(int dx, int dy){
    		this.x = x + dx;
    		this.y = y + dy;
    	}
    	public void Translate(Point t){
    		this.x = x + t.x;
    		this.y = y + t.y;
    	}
    	public void Print(){
    		System.out.println("Inintial location: (" + this.x + "," + this.y + ")");
    	}
    }
    and the code I'm trying to get to work but I'm not sure what I'm doing wrong.
    Java Code:
    public class ClassTest {
    	public static void main(String[] args){
    
    		Point p1 = new Point();
    		p1.Point(5, 3);
    		p1.Print();
    	}
    }
    and I keep getting this error and I'm not sure what is wrong and googling it didn't

    ClassTest.java:11: error: cannot find symbol
    p1,Point(5, 3);
    ^
    symbolL method Point(int,int)
    location: variable p1 of type Point
    1 error

    I'm sure the answer is really dumb but it's late and I've been trying forever to get it to work and I could really use some help.
    Thanks
    Last edited by Omgium; 12-03-2012 at 12:38 PM.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: using classes help

    Please use [code] tags [/code] when posting code.
    Java Code:
    p1.Point(5, 3);
    The Point class has no method Point(int, int).
    It has a constructor, but that is not a method.
    It also has a Translate(int, int), but that is not what you have called.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    Omgium is offline Member
    Join Date
    Dec 2012
    Posts
    3
    Rep Power
    0

    Default Re: using classes help

    Thanks for the reply and I edited the OP to have tags.

    so may I ask another dumb question:
    What is the difference between
    Java Code:
    public Point()
    and
    Java Code:
    public void Point()
    ?

  4. #4
    Omgium is offline Member
    Join Date
    Dec 2012
    Posts
    3
    Rep Power
    0

    Default Re: using classes help

    Also lets say I wanted to make an array of points and then give each one seperate values. Could I implement that like this?
    Java Code:
    Point[] p = new Point[5];
    for(int i = 0; i < 5; i++){
    	p[i] = Point(i, i*2);
    }

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: using classes help

    Quote Originally Posted by Omgium View Post
    Thanks for the reply and I edited the OP to have tags.

    so may I ask another dumb question:
    What is the difference between
    Java Code:
    public Point()
    and
    Java Code:
    public void Point()
    ?
    The first one is a constructor and is only used when constructing a new object (the 'new' keyword).
    The second would be a method.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: using classes help

    Quote Originally Posted by Omgium View Post
    Also lets say I wanted to make an array of points and then give each one seperate values. Could I implement that like this?
    Java Code:
    Point[] p = new Point[5];
    for(int i = 0; i < 5; i++){
    	p[i] = Point(i, i*2);
    }
    Yes, that would work.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Association Classes for these classes
    By kevinkhan in forum New To Java
    Replies: 9
    Last Post: 03-21-2012, 06:22 PM
  2. Classes Help!!! two classes with object question.
    By stuckonjava in forum New To Java
    Replies: 16
    Last Post: 02-10-2012, 02:39 AM
  3. Use classes inside of other classes
    By BlankFile in forum New To Java
    Replies: 2
    Last Post: 02-06-2012, 02:51 PM
  4. A little help with classes.
    By ThrashingBoy in forum New To Java
    Replies: 8
    Last Post: 06-10-2010, 10:52 AM
  5. Using a JAR from other classes
    By Joe2003 in forum Advanced Java
    Replies: 1
    Last Post: 01-02-2008, 08:08 PM

Posting Permissions

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