Your program should: // get an integer from the user and returns it // make 3 ca
ID: 3790100 • Letter: Y
Question
Your program should:
// get an integer from the user and returns it
// make 3 calls to this function:
// 1. To get the radius of the circle from the user and return it to main (look up the formula if you aren't sure)
// 2. To get the length of the rectangle from the user and return it to main
// 3. To get the width of the rectangle from the user and return it to main (Hint: you can prompt from the main function BEFORE you call your function. You do NOT need to prompt from inside this function) int GetInt(void);
// takes two arguments, the length of the square returns the area int CalculateAreaRec(int length, int width);
// takes one argument, the radius of the circle and returns the area double CalculateAreaCir(int radius);
no calculations for the Areas may be done in the main function and the code should be well commented!
Explanation / Answer
Interface shape
{
double area();
double display();
double pi=3.14;
}
class circle implements shape
{
private double r;
circle (double radius)
{
r=radius;
}
public void set(double radius)
{
r=radius;
}
public double area()
{
return pi*r*r;
}
public void display()
{
system.out.println("Area(circle); " +area());
}
}
Class Rectangle implements shape
{
private double l,w;
Rectangle(double length,double width)
{
l=length;
w=width;
}
public void set(double length,double width)
{
l=length;
w=width;
}
public double area()
{
return l*w;
}
system.out.ln("Area(rectangle);"area());
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.