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

Thread: accessor and modifier method exercise; exercise 100

  1. #1
    Member
    Join Date
    Aug 2013
    Posts
    101
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cool accessor and modifier method exercise; exercise 100

    Non-editable code:

     
    public class APPoint 
      { 
        private double myX; 
        private double myY; 
     
        public APPoint( double x, double y ) 
        { 
          myX = x; 
          myY = y; 
        } 
     
        public void move( double x, double y ) 
        { 
          myX += x; 
          myY += y; 
        } 
     
        public double getX()  
        { 
          return myX; 
        } 
     
        public void setX( double x ) 
        { 
          myX = x; 
        } 
     
        public double getY() 
        { 
          return myY; 
        }

    Here's my code:

     
    public double setY(){
        return myY = y;   
    }

    Here is the continuing, non editable code:

      } 
     
      public static void main( String[] args ) 
      { 
        APPoint a = new APPoint( 15.0, 4.0 ); 
        APPoint b = new APPoint( -4.0, 8.2 ); 
     
        a.setX( 0.0 ); 
        b.setY( a.getY() ); 
     
        System.out.println( "a is (" + a.getX() + "," + a.getY() + ")" ); 
        System.out.println( "b is (" + b.getX() + "," + b.getY() + ")" ); 
      }

    I'm looking up tutorials on how to do this stuff myself, but I'm just asking in case I happen to stumble upon something that might work. I'm just looking for suggestions on tutorials, articles, etc that may help. I'm not looking for specific help yet. I mean, since I want to try to figure this stuff out on my own but I thought that getting suggestions from a forum might help. I'm using youtube and google already. Lol.


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

    Default Re: accessor and modifier method exercise; exercise 100

    How's this different from your other thread?

  3. #3
    Member
    Join Date
    Aug 2013
    Posts
    101
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: accessor and modifier method exercise; exercise 100

    It's a different part of the code to complete. Maybe I should look at my old thread. Thanks, haha. I didn't notice that.

    --- Update ---

    made it work:

    public double setY(double y){
        myY = y;
        return y;
    }

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: accessor and modifier method exercise; exercise 100

    Why return the value of the arg passed in the method call?
    settor methods don't normally return a value.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Member
    Join Date
    Aug 2013
    Posts
    101
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: accessor and modifier method exercise; exercise 100

    Alright. Good point. It still worked though. Your saying part of that was unneeded? Ok. It gave me an error because it wouldn't return any value. It said "no return type." That's all. It wouldn't work until I returned y. Does that mean something's still wrong?

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: accessor and modifier method exercise; exercise 100

    Settors are not intended to return a value. They are normally defined to return void.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Member
    Join Date
    Aug 2013
    Posts
    101
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: accessor and modifier method exercise; exercise 100

    Well, that's a weird error then. Lol.

Similar Threads

  1. Exercise 98: how to write a main method with what I'm given
    By ghostheadx in forum What's Wrong With My Code?
    Replies: 11
    Last Post: December 30th, 2013, 01:23 AM
  2. Exercise 95 (I KNOW, I'm at an earlier exercise)
    By ghostheadx in forum What's Wrong With My Code?
    Replies: 9
    Last Post: December 24th, 2013, 08:42 PM
  3. Exercise 86
    By ghostheadx in forum What's Wrong With My Code?
    Replies: 11
    Last Post: December 7th, 2013, 11:31 PM
  4. Exercise
    By keepStriving in forum What's Wrong With My Code?
    Replies: 5
    Last Post: October 21st, 2013, 06:58 PM
  5. Is this what my exercise want?
    By Arkeshen in forum Java Theory & Questions
    Replies: 3
    Last Post: May 16th, 2011, 04:51 PM

Tags for this Thread