Results 1 to 2 of 2
  1. #1
    cstokes91 is offline Member
    Join Date
    Jan 2010
    Posts
    1
    Rep Power
    0

    Default Construct a rectangle

    Hello, I have seen problems similar to mine but I have had no luck piecing other problems together to get my own end result... Here is the problem.

    Write a PerimeterTester program that constructs a Rectangle object and then computes and prints its perimeter. Use the getWidth and getHeight methods. Also print the expected answer.

    Here is what I have so far..

    import java.awt.Rectangle;

    public class assignment2
    {
    public static void main(String[] args)
    {
    Rectangle box = new Rectangle(5, 10, 20, 30);

    // Move the rectangle
    box.translate (15,25);
    from this point I have no clue where to go with it.

  2. #2
    [RaIdEn] is offline Senior Member
    Join Date
    Oct 2009
    Location
    California,US
    Posts
    201
    Rep Power
    5

    Default

    first make a constructor which constructs the Rectangle with width and rectangle as its parameters

    Java Code:
    public Rectangle(int w,int h)
    {..}
    then
    write respective getters methods for width and height.

    and using main method and calculating respective perimeters for the rectangle.
    2nd way ..

    Java Code:
    import java.awt.Rectangle;
    
    public class assignment2
    {
    public static void main(String[] args)
    {
    Rectangle box = new Rectangle(5, 10, 20, 30); // over here 20 and 30 is the width and                    //height by http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Rectangle.html#Rectangle(int, int, int, int)
    
    // Move the rectangle 
    //box.translate (15,25); <----- why?aernt you trying to find perimeter?
    
    so try using 
    
    2(box.getWidth()+box.getHeight())=perimeter

Similar Threads

  1. [SOLVED] Array Programming Construct?
    By iPetey in forum New To Java
    Replies: 3
    Last Post: 04-09-2009, 02:53 AM
  2. How to construct my finished program?
    By matpj in forum New To Java
    Replies: 0
    Last Post: 01-14-2009, 05:37 PM
  3. [SOLVED] Construct parents using tree path.
    By Melki in forum AWT / Swing
    Replies: 2
    Last Post: 09-23-2008, 04:54 PM
  4. How to construct checkbox in rtf document using iText?
    By soumyanil in forum Advanced Java
    Replies: 0
    Last Post: 07-28-2008, 11:05 AM
  5. Replies: 3
    Last Post: 12-05-2007, 02:22 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
  •