public abstract class Shape { public Shape() { } public abstract double area() ; public String who() { return "Shape" ;

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

public abstract class Shape { public Shape() { } public abstract double area() ; public String who() { return "Shape" ;

Post by answerhappygod »

public abstract class Shape {
public Shape() { }
public abstract double area()
;
public String
who() { return "Shape" ; }
}
public class Circle extends Shape {
private int radius ;
public Circle( int r )
{
radius = r ;
}
@Override
public double area()
{
return Math.PI * radius * radius
;
}
}
public class Square extends Shape {
private int _sideLength ;
public Square( int sideLength
)
{
/* TODO question 45 */
}
@Override
public double area()
{
return _sideLength *
_sideLength ;
}
}
Implement the Square constructor, and make sure it
throws an exception when the input parameter is not a valid length.
The input parameter must be positive to be considered
valid.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply