GeometricObject.java
public interface GeometricObject {
//Declaring abstract methods
public double getPerimeter();
public double getArea();
}
___________________________________________
Circle.java
public class Circle implements GeometricObject {
//Declaring variable
double radius = 1.0;
//Declaring constant
public static final double PI = 3.14159;
//Parameterized constructor
public Circle(double radius) {
super();
this.radius = radius;
}
//Setters and getters
public double getRadius() {
return radius;
}
public void setRadius(double radius) {
this.radius = radius;
}
//getPerimeter() calculates the perimeter and return it
@Override
public double getPerimeter() {
return 2 * PI * this.radius;
}
//getArea() calculates area and return it
@Override
public double getArea() {
return PI * this.radius * this.radius;
}
}
___________________________________________
Resizable.java
public interface Resizable {
//Declaring abstract method
public void resize(int percent);
}
_________________________________________________
ResizableCircle.java
public class ResizableCircle extends Circle implements Resizable {
//parameterized ResizableObject
public ResizableCircle(double radius) {
super(radius);
}
//resize() method will change the radius of the circle based on percent
@Override
public void resize(int percent) {
double radius=getRadius();
radius=radius+((radius*percent)/100);
setRadius(radius);
}
}
___________________________________________
DriverClass.java
import java.text.DecimalFormat;
public class DriverClass {
public static void main(String[] args) {
//DecimalFormat Object is used to format the number
DecimalFormat df=new DecimalFormat("#.##");
//Creates an circle object by passing radius as parameter
Circle c=new Circle(10);
//Displaying the perimeter of the circle
System.out.println("Perimeter of the Circle :"+df.format(c.getPerimeter()));
//Displaying the area of the circle
System.out.println("Area of the Circle :"+df.format(c.getArea()));
//creating the object of the Resizable object by passing radius as parameter
ResizableCircle rc=new ResizableCircle(20);
//Displaying perimeter and area of the circle before resizing the radius
System.out.println(" _______Before Resizing the Radius_______");
System.out.println("Perimeter of the Circle :"+df.format(rc.getPerimeter()));
System.out.println("Area of the Circle :"+df.format(rc.getArea()));
//Performing the resize
rc.resize(50);
//Displaying perimeter and area of the circle after resizing the radius
System.out.println(" _______After Resizing the Radius_______");
System.out.println("Perimeter of the Circle :"+df.format(rc.getPerimeter()));
System.out.println("Area of the Circle :"+df.format(rc.getArea()));
}
}
________________________________________________
Output:
Perimeter of the Circle :62.83
Area of the Circle :314.16
_______Before Resizing the Radius_______
Perimeter of the Circle :125.66
Area of the Circle :1256.64
_______After Resizing the Radius_______
Perimeter of the Circle :188.5
Area of the Circle :2827.43
_______________________________________Thank YOu
Solution
GeometricObject.java
public interface GeometricObject {
//Declaring abstract methods
public double getPerimeter();
public double getArea();
}
___________________________________________
Circle.java
public class Circle implements GeometricObject {
//Declaring variable
double radius = 1.0;
//Declaring constant
public static final double PI = 3.14159;
//Parameterized constructor
public Circle(double radius) {
super();
this.radius = radius;
}
//Setters and getters
public double getRadius() {
return radius;
}
public void setRadius(double radius) {
this.radius = radius;
}
//getPerimeter() calculates the perimeter and return it
@Override
public double getPerimeter() {
return 2 * PI * this.radius;
}
//getArea() calculates area and return it
@Override
public double getArea() {
return PI * this.radius * this.radius;
}
}
___________________________________________
Resizable.java
public interface Resizable {
//Declaring abstract method
public void resize(int percent);
}
_________________________________________________
ResizableCircle.java
public class ResizableCircle extends Circle implements Resizable {
//parameterized ResizableObject
public ResizableCircle(double radius) {
super(radius);
}
//resize() method will change the radius of the circle based on percent
@Override
public void resize(int percent) {
double radius=getRadius();
radius=radius+((radius*percent)/100);
setRadius(radius);
}
}
___________________________________________
DriverClass.java
import java.text.DecimalFormat;
public class DriverClass {
public static void main(String[] args) {
//DecimalFormat Object is used to format the number
DecimalFormat df=new DecimalFormat("#.##");
//Creates an circle object by passing radius as parameter
Circle c=new Circle(10);
//Displaying the perimeter of the circle
System.out.println("Perimeter of the Circle :"+df.format(c.getPerimeter()));
//Displaying the area of the circle
System.out.println("Area of the Circle :"+df.format(c.getArea()));
//creating the object of the Resizable object by passing radius as parameter
ResizableCircle rc=new ResizableCircle(20);
//Displaying perimeter and area of the circle before resizing the radius
System.out.println(" _______Before Resizing the Radius_______");
System.out.println("Perimeter of the Circle :"+df.format(rc.getPerimeter()));
System.out.println("Area of the Circle :"+df.format(rc.getArea()));
//Performing the resize
rc.resize(50);
//Displaying perimeter and area of the circle after resizing the radius
System.out.println(" _______After Resizing the Radius_______");
System.out.println("Perimeter of the Circle :"+df.format(rc.getPerimeter()));
System.out.println("Area of the Circle :"+df.format(rc.getArea()));
}
}
________________________________________________
Output:
Perimeter of the Circle :62.83
Area of the Circle :314.16
_______Before Resizing the Radius_______
Perimeter of the Circle :125.66
Area of the Circle :1256.64
_______After Resizing the Radius_______
Perimeter of the Circle :188.5
Area of the Circle :2827.43
_______________________________________Thank YOu

GeometricObject.javapublic interface GeometricObject { Declari.pdf

  • 1.
    GeometricObject.java public interface GeometricObject{ //Declaring abstract methods public double getPerimeter(); public double getArea(); } ___________________________________________ Circle.java public class Circle implements GeometricObject { //Declaring variable double radius = 1.0; //Declaring constant public static final double PI = 3.14159; //Parameterized constructor public Circle(double radius) { super(); this.radius = radius; } //Setters and getters public double getRadius() { return radius; } public void setRadius(double radius) { this.radius = radius; } //getPerimeter() calculates the perimeter and return it @Override public double getPerimeter() { return 2 * PI * this.radius; } //getArea() calculates area and return it @Override
  • 2.
    public double getArea(){ return PI * this.radius * this.radius; } } ___________________________________________ Resizable.java public interface Resizable { //Declaring abstract method public void resize(int percent); } _________________________________________________ ResizableCircle.java public class ResizableCircle extends Circle implements Resizable { //parameterized ResizableObject public ResizableCircle(double radius) { super(radius); } //resize() method will change the radius of the circle based on percent @Override public void resize(int percent) { double radius=getRadius(); radius=radius+((radius*percent)/100); setRadius(radius); } } ___________________________________________ DriverClass.java import java.text.DecimalFormat; public class DriverClass { public static void main(String[] args) { //DecimalFormat Object is used to format the number DecimalFormat df=new DecimalFormat("#.##");
  • 3.
    //Creates an circleobject by passing radius as parameter Circle c=new Circle(10); //Displaying the perimeter of the circle System.out.println("Perimeter of the Circle :"+df.format(c.getPerimeter())); //Displaying the area of the circle System.out.println("Area of the Circle :"+df.format(c.getArea())); //creating the object of the Resizable object by passing radius as parameter ResizableCircle rc=new ResizableCircle(20); //Displaying perimeter and area of the circle before resizing the radius System.out.println(" _______Before Resizing the Radius_______"); System.out.println("Perimeter of the Circle :"+df.format(rc.getPerimeter())); System.out.println("Area of the Circle :"+df.format(rc.getArea())); //Performing the resize rc.resize(50); //Displaying perimeter and area of the circle after resizing the radius System.out.println(" _______After Resizing the Radius_______"); System.out.println("Perimeter of the Circle :"+df.format(rc.getPerimeter())); System.out.println("Area of the Circle :"+df.format(rc.getArea())); } } ________________________________________________ Output: Perimeter of the Circle :62.83 Area of the Circle :314.16 _______Before Resizing the Radius_______ Perimeter of the Circle :125.66 Area of the Circle :1256.64 _______After Resizing the Radius_______
  • 4.
    Perimeter of theCircle :188.5 Area of the Circle :2827.43 _______________________________________Thank YOu Solution GeometricObject.java public interface GeometricObject { //Declaring abstract methods public double getPerimeter(); public double getArea(); } ___________________________________________ Circle.java public class Circle implements GeometricObject { //Declaring variable double radius = 1.0; //Declaring constant public static final double PI = 3.14159; //Parameterized constructor public Circle(double radius) { super(); this.radius = radius; } //Setters and getters public double getRadius() { return radius; } public void setRadius(double radius) { this.radius = radius; } //getPerimeter() calculates the perimeter and return it @Override
  • 5.
    public double getPerimeter(){ return 2 * PI * this.radius; } //getArea() calculates area and return it @Override public double getArea() { return PI * this.radius * this.radius; } } ___________________________________________ Resizable.java public interface Resizable { //Declaring abstract method public void resize(int percent); } _________________________________________________ ResizableCircle.java public class ResizableCircle extends Circle implements Resizable { //parameterized ResizableObject public ResizableCircle(double radius) { super(radius); } //resize() method will change the radius of the circle based on percent @Override public void resize(int percent) { double radius=getRadius(); radius=radius+((radius*percent)/100); setRadius(radius); } } ___________________________________________ DriverClass.java import java.text.DecimalFormat; public class DriverClass {
  • 6.
    public static voidmain(String[] args) { //DecimalFormat Object is used to format the number DecimalFormat df=new DecimalFormat("#.##"); //Creates an circle object by passing radius as parameter Circle c=new Circle(10); //Displaying the perimeter of the circle System.out.println("Perimeter of the Circle :"+df.format(c.getPerimeter())); //Displaying the area of the circle System.out.println("Area of the Circle :"+df.format(c.getArea())); //creating the object of the Resizable object by passing radius as parameter ResizableCircle rc=new ResizableCircle(20); //Displaying perimeter and area of the circle before resizing the radius System.out.println(" _______Before Resizing the Radius_______"); System.out.println("Perimeter of the Circle :"+df.format(rc.getPerimeter())); System.out.println("Area of the Circle :"+df.format(rc.getArea())); //Performing the resize rc.resize(50); //Displaying perimeter and area of the circle after resizing the radius System.out.println(" _______After Resizing the Radius_______"); System.out.println("Perimeter of the Circle :"+df.format(rc.getPerimeter())); System.out.println("Area of the Circle :"+df.format(rc.getArea())); } } ________________________________________________ Output: Perimeter of the Circle :62.83
  • 7.
    Area of theCircle :314.16 _______Before Resizing the Radius_______ Perimeter of the Circle :125.66 Area of the Circle :1256.64 _______After Resizing the Radius_______ Perimeter of the Circle :188.5 Area of the Circle :2827.43 _______________________________________Thank YOu