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: getPerimeter of a rectangle

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

    Default getPerimeter of a rectangle

    public class Rectangle {
     
     
     
    	public static void main(String[] args) {
     
     
    	}
     
    	 public Rectangle(int x, int y, int height, int width)
     
    	 {
     
    		 Rectangle r = new Rectangle(x, y, height, width);
     
     
    	 }
    	 public int getPerimeter()
    	 {
     
     
    		return p;
     
    	 }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: getPerimeter of a rectangle

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

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

    Default Re: getPerimeter of a rectangle

    x and y are the co-ordinates of upper left corner and height and width are given as above. It suppose to return perimeter of the rectangle. I could n't find where to start? I know the formula to get Perimeter = 2(height + width) but what do I do with it's coordinate x and y? It should be done with methods so I layout the code structure as you see above. Please give me some ideas on this.

    --- Update ---

    Yes, I was typing it. It should be up by now.

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

    Default Re: getPerimeter of a rectangle

    what do I do with it's coordinate x and y
    The x,y are the location of the rectangle. They are not used in computing the perimeter.
    If you don't understand my answer, don't ignore it, ask a question.

  5. The Following User Says Thank You to Norm For This Useful Post:

    JlovesJava (February 22nd, 2013)

  6. #5
    Junior Member
    Join Date
    Jun 2012
    Posts
    18
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: getPerimeter of a rectangle

    I think this is what you're looking for
    ********* Code removed Please don't spoonfeed

  7. The Following User Says Thank You to usama8800 For This Useful Post:

    JlovesJava (February 22nd, 2013)

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

    Default Re: getPerimeter of a rectangle

    I got ' r can't be resolved error'; how should I construct Rectangle r?

  9. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: getPerimeter of a rectangle

    The formula in your post#3 should work.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Rectangle + Origo
    By NeewBieGeKo in forum Java Theory & Questions
    Replies: 1
    Last Post: November 27th, 2012, 01:51 PM
  2. Rectangle/Ellipse program help
    By ja3n in forum AWT / Java Swing
    Replies: 1
    Last Post: March 1st, 2012, 05:51 AM
  3. Gradual appearance of Rectangle...
    By rdheepan in forum Web Frameworks
    Replies: 5
    Last Post: January 13th, 2012, 12:07 AM
  4. Unable to draw a rectangle
    By n00b in forum AWT / Java Swing
    Replies: 3
    Last Post: November 1st, 2011, 07:32 AM
  5. Rectangle questions
    By stacksofamber in forum Java Theory & Questions
    Replies: 3
    Last Post: September 5th, 2011, 12:43 PM