Results 1 to 6 of 6
Thread: using classes help
- 12-03-2012, 11:12 AM #1
Member
- Join Date
- Dec 2012
- Posts
- 3
- Rep Power
- 0
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:
and the code I'm trying to get to work but I'm not sure what I'm doing wrong.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 I keep getting this error and I'm not sure what is wrong and googling it didn'tJava Code:public class ClassTest { public static void main(String[] args){ Point p1 = new Point(); p1.Point(5, 3); p1.Print(); } }
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.
ThanksLast edited by Omgium; 12-03-2012 at 11:38 AM.
- 12-03-2012, 11:34 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Re: using classes help
Please use [code] tags [/code] when posting code.
The Point class has no method Point(int, int).Java Code:p1.Point(5, 3);
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.
- 12-03-2012, 11:52 AM #3
Member
- Join Date
- Dec 2012
- Posts
- 3
- Rep Power
- 0
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 betweenandJava Code:public Point()
?Java Code:public void Point()
- 12-03-2012, 12:12 PM #4
Member
- Join Date
- Dec 2012
- Posts
- 3
- Rep Power
- 0
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); }
- 12-03-2012, 02:08 PM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
- 12-03-2012, 02:08 PM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Similar Threads
-
Association Classes for these classes
By kevinkhan in forum New To JavaReplies: 9Last Post: 03-21-2012, 05:22 PM -
Classes Help!!! two classes with object question.
By stuckonjava in forum New To JavaReplies: 16Last Post: 02-10-2012, 01:39 AM -
Use classes inside of other classes
By BlankFile in forum New To JavaReplies: 2Last Post: 02-06-2012, 01:51 PM -
A little help with classes.
By ThrashingBoy in forum New To JavaReplies: 8Last Post: 06-10-2010, 09:52 AM -
Using a JAR from other classes
By Joe2003 in forum Advanced JavaReplies: 1Last Post: 01-02-2008, 07:08 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks