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 8 of 8

Thread: Creating a Point.class

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Creating a Point.class

    Hey everyone,
    I have an assignment that's due tomorrow and I am completely stuck and was hoping to get some help. My assignment is to create a Point object that represents an x,y point. Here is an outline of the object that the teacher gave us. Any help would be much appreciated! -Jon

    The instance data stores its x and y coordinates.
    The constructor lets you set x and y when you create a Point.
    There is a method called getX for asking a Point what its x-coordinate is.
    There is a method called getY for asking a Point what its y-coordinate is.
    There is a method called setXY that lets you change the coordinates of a Point.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,312
    Thanks
    56
    Thanked 2,373 Times in 2,344 Posts

    Default Re: Creating a Point.class

    Have you looked at the java SE's Point class? The name Point is used by the Java SE. Using the same name will cause confusion.

    What have you tried?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Feb 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Creating a Point.class

    Hey Norm,

    I was unaware of this, but my teacher specifically asked us to label the new class "Point". Here is what I have gotten so far

    public class Point {

    private int x, y;

    public Point(int x, int y) {

    }

    public int getX() {

    return x;

    }

    public int getY() {

    return y;

    }
    }

    So I have my instance data, constructor, but am not sure of how to tie in x,y data to the getX and setXY. I know it is not much of a start and probably contains some errors, but I am at a dead end. And sorry about the vagueness of the first post. I am not looking for you to write my code for me. I just need some direction. Thanks for your time. -Jon

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,312
    Thanks
    56
    Thanked 2,373 Times in 2,344 Posts

    Default Re: Creating a Point.class

    The constructor needs to save the x,y values it receives.
    The get method should return the current value of the variable. Yours look OK.
    setXY() would be similar to the constructor: save x and y

    When you post code, please wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Feb 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Creating a Point.class

    Thanks, that helped a lot. I am now stuck on the setXY() section and was wondering how setXY() works? Do you need user input and use the Scanner class? -Jon

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,312
    Thanks
    56
    Thanked 2,373 Times in 2,344 Posts

    Default Re: Creating a Point.class

    Ask your teacher what he intended. I suggested that setXY() do the same as the constructor.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Feb 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Creating a Point.class

    Awesome Norm, just finished the program. Thanks for your help. Sorry for my lack of java and forum ettiquette, I am new to the game. -Jon

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,312
    Thanks
    56
    Thanked 2,373 Times in 2,344 Posts

    Default Re: Creating a Point.class

    No problem. I'm sure you'll improve with more experience.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Creating and implementing class for creating a calendar object
    By kumalh in forum Object Oriented Programming
    Replies: 3
    Last Post: July 29th, 2011, 09:40 AM
  2. [SOLVED] Creating A Class
    By cb5950 in forum Object Oriented Programming
    Replies: 1
    Last Post: March 31st, 2011, 08:27 AM
  3. [SOLVED] Class Creating Help
    By pitchblack in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 1st, 2011, 11:25 PM
  4. Help with creating a class
    By cdawg_2010 in forum Loops & Control Statements
    Replies: 4
    Last Post: November 1st, 2010, 08:04 AM
  5. Creating a class file
    By ipatch in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 8th, 2009, 07:19 PM