
Romeo ..
asked 02/18/19oops in python.
- Write a program using object oriented method to calculate the area. It should require two attributes width W and Height H.
2. Write a program using OOP method to calculate the area. It should require two values of attributes W and H (the user will enter the values of w and h in run time).
1 Expert Answer

Patrick B. answered 02/19/19
Math and computer tutor/teacher
import java.io.*;
class RectangleArea
{
private double width;
private double length;
//constructor
RectangleArea ( double l, double w)
{
width = w; length = l;
}
public double GetLength() { return(length); }
public double GetWidth() { return(width); }
public double Area() { return(width*length); }
public double PromptForDouble( String promptMsg) throws IOException
{
double dblNum=0;
String inbuff=null;
Console console = System.console();
do
{
System.out.print(promptMsg);
inbuff = console.readLine();
dblNum = Double.parseDouble(inbuff);
} while (dblNum<=0);
return(dblNum);
} //PromptForDouble
public static void main( String args[])
{
double l,w;
l=w=0;
RectangleArea dummyInput = new RectangleArea(0,0);
try
{
l = dummyInput.PromptForDouble(" Please input the length :>");
w = dummyInput.PromptForDouble(" Please input the width :>");
}
catch (IOException ex) { System.out.println(" input exception has occurred"); }
RectangleArea myRectangleArea = new RectangleArea(l,w);
System.out.println("**********************************************************");
System.out.println(" Width is " + myRectangleArea.GetWidth() );
System.out.println(" Length is " + myRectangleArea.GetLength() );
System.out.println(" Area is " + myRectangleArea.Area() );
System.out.println("************************************************************");
} //main
}//class
Still looking for help? Get the right answer, fast.
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
Larry C.
What sort of shapes are you trying to calculate the area of?02/19/19