File size: 2,777 Bytes
c574d3a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
// class Shapes {
// double findArea(int radius) {
// return 3.14 * radius * radius;
// }
// double findArea(double side) {
// return side * side;
// }
// double findArea(double length, double breadth) {
// return length * breadth;
// }
// }
// interface Shapes {
// double area();
// }
// class Circle implements Shapes {
// static final double PI = 3.14;
// private double radius;
// Circle() {
// }
// Circle(double radius) {
// this.radius = radius;
// }
// public double getRadius() {
// return this.radius;
// }
// public void setRadius(double radius) {
// this.radius = radius;
// }
// public double area() {
// return PI * radius * radius;
// }
// @Override
// public String toString() {
// return "Circle [radius=" + radius + ", area=" + area() + "]";
// }
// }
// class Rectangle implements Shapes {
// private double length;
// private double breadth;
// Rectangle() {
// }
// Rectangle(double length, double breadth) {
// this.length = length;
// this.breadth = breadth;
// }
// public double getLength() {
// return this.length;
// }
// public void setLength(double length) {
// this.length = length;
// }
// public double getBreadth() {
// return this.breadth;
// }
// public void setBreadth(double breadth) {
// this.breadth = breadth;
// }
// public double area() {
// return length * breadth;
// }
// @Override
// public String toString() {
// return "Rectangle [breadth=" + breadth + ", length=" + length + ", area=" + area() + "]";
// }
// }
interface Shapes {
double area(double x);
}
public class ShapesDriver {
public static void main(String[] args) {
// Shapes shapes = new Shapes();
// String name1 = "Akash";
// String name2 = "Akash";
// name1 = "Akash Das";
// name2 = "Akash Das";
// name1 = "Akash";
// System.out.println("Area of Rectangle:: " + shapes.findArea(5));
// System.out.println("Area of square:: " + shapes.findArea(5.0));
// System.out.println("Area of rectangle:: " + shapes.findArea(5, 6));
// Shapes circle = new Circle(5);
// Shapes rectangle = new Rectangle(5, 6);
// System.out.println(circle);
// System.out.println(rectangle);
// Shapes circle = new Shapes() {
// public double area(double radius) {
// return 3.14 * radius * radius;
// }
// };
Shapes circle = radius -> 3.14 * radius * radius;
System.out.println(circle.area(5));
}
} |