Oblong


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Oblong

  1. #1
    Join Date
    Dec 2004
    Posts
    46

    Oblong

    Hi,

    I have wrote a program that allows me to enter the length of an oblong and then the height of an oblong and then it calculates the Oblong length, Oblong height , Oblong area, Oblong perimeter.

    For example:
    Please enter the length of your oblong: 20
    Please enter the height of your oblong: 20
    Oblong length is 20.0
    Oblong height is 20.0
    Oblong area is 400.0
    Oblong perimeter is 80.0

    Code:

    public class Oblong2
    {
    public static void main (String[] args)
    {
    /* declare two variables to hold the length and height
    of the oblong as input by the user */
    double oblongLength, oblongHeight;
    // declare a reference to an Oblong object
    Oblong myOblong;
    // now get the values from the user
    System.out.print("Please enter the length of your oblong: ");
    oblongLength = EasyIn.getDouble();
    System.out.print("Please enter the height of your oblong: ");
    oblongHeight = EasyIn.getDouble();
    // create a new Oblong object
    myOblong = new Oblong(oblongLength, oblongHeight);
    /* use the various methods of the Oblong class to display the
    the lenght, height, area and perimeter of the Oblong */
    System.out.println("Oblong length is " + myOblong.getLength());
    System.out.println("Oblong height is " + myOblong.getHeight());
    System.out.println("Oblong area is " + myOblong.calculateArea());
    System.out.println("Oblong perimeter is "
    + myOblong.calculatePerimeter());
    }

    }


    Now I want to make this so that I am able to input the length and height of two oblongs and then see a message on the screen saying which one, if any, has the greater area.

    Any help would be appeciated.

  2. #2
    Join Date
    Aug 2004
    Location
    On the net
    Posts
    38
    Hi Buddy,

    Your logic is fine but I feel that you can acheive at what you asked if u make use of the object oriented concept well.

    I'm assuming that you want to make use of the same class and create two objects and check which one's area is greater.

    If this is the case then you have to shift the entire logic(calculation of perimeter and area) into the class definition and then create two objects of the class in the main function and then retrieve their areas and compare them.

    Thats it. I suppose your requirement will be over if you do that.

    You can ask me if I'm not clear.

    Good Luck :-)

    Thanks
    Narayana.

  3. #3
    Join Date
    Nov 2004
    Location
    Minnesota
    Posts
    99
    WillisTi,

    You also may wish to check your computation of area and perimeter. What you have calculated there is the area and perimeter of a rectangle (which is larger than an oblong). So if you're doing this for a class project, you may wish to plug in the correct formula.

  4. #4
    Join Date
    Dec 2004
    Posts
    46
    Thanks for your suggestions

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center