Results 1 to 7 of 7
  1. #1
    ssssami is offline Member
    Join Date
    Sep 2010
    Posts
    3
    Rep Power
    0

    Default how i can do this in java main and class point

    write a class named Point that include two integer fields x and y and the following methods...
    1. a constructor with no parameters that set both x=y=0
    2. a constructor with one parameter a that sets x=y=a
    3. a constructor with two parameters a,b that sets x=a and y=b
    4. two get methods to return x and y
    5. two set methods to set a new values to x and y
    6. getLocation method which return a string of the location of the point

    after that build a main method in which great three points from the three different constructors and print out its x-y values and location


    please any one help me i need this program use netbeans

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,391
    Rep Power
    25

    Default

    Have you started writing code for your assignment yet?
    If you have any questions, problems or errors, please post them here.

  3. #3
    ssssami is offline Member
    Join Date
    Sep 2010
    Posts
    3
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    Have you started writing code for your assignment yet?
    If you have any questions, problems or errors, please post them here.
    in class Point i write this code

    Java Code:
    public class Point {
        int x,y;
        
        /** Creates a new instance of Point */
        public Point() {
            x=y=0;
        }
          public Point(int a) {
            x=y=a;
        }
              public Point(int a, int b) {
            x=a;
            y=b;
        }
            public Integer getX() {
            return x;
        }
    
        public Integer getY() {
            return y;
        }
        
            public void setX(int xx) {
            this.x = xx;
        }
    
        public void setY(int yy) {
            this.y = yy;
        }
        
     public Point getLocation() {
      return new Point(x, y);
        }
    
    
    }
    but iam new to java programming

    i do not know what i must write in main

    please help me

    i do not understand this lines i need understand it and code for applay it please

    6. getLocation method which return a string of the location of the point

    after that build a main method in which great three points from the three different constructors and print out its x-y values and location


    please any one help me i need this program use netbeans

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,391
    Rep Power
    25

    Default

    getLocation method which return a string of the location of the point
    What do you want the returned String to look like? Like this: x=2, y=4
    Write a method that returns a String, build some String and return it

  5. #5
    ssssami is offline Member
    Join Date
    Sep 2010
    Posts
    3
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    What do you want the returned String to look like? Like this: x=2, y=4
    Write a method that returns a String, build some String and return it

    can you give me simple code do this? please and where i put this code

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,391
    Rep Power
    25

    Default

    Here is a sample get method taken from your code. It uses int vs String so you would need to change where int is used to String and change the value that is returned to be the String you want returned:
    Java Code:
     public Integer getY() {
            return y;
        }

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,234
    Rep Power
    19

Similar Threads

  1. Replies: 2
    Last Post: 04-01-2009, 08:37 AM
  2. different multiple public class and main class
    By mr idiot in forum New To Java
    Replies: 2
    Last Post: 01-01-2009, 12:10 PM
  3. Replies: 5
    Last Post: 10-06-2008, 12:11 AM
  4. How to create main class link to another two class?
    By pearllymary78 in forum New To Java
    Replies: 6
    Last Post: 07-16-2008, 11:02 PM
  5. Replies: 1
    Last Post: 08-06-2007, 09:11 AM

Posting Permissions

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