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.
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
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
// 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 "
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.
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 :-)
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
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