-
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.
-
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.
-
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.
-
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
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks