summary refs log tree commit diff stats
path: root/java/code/AbstractShapeCalculations.java
diff options
context:
space:
mode:
authorSudipto Mallick <smlckz@termux-alpine>2024-01-28 06:38:55 +0000
committerSudipto Mallick <smlckz@termux-alpine>2024-01-28 06:38:55 +0000
commitfc4d96a9e3e20f8ddf035c16fc32b1effb75481b (patch)
tree4e13b2606e94e2098d1a288b051603cfc36d983b /java/code/AbstractShapeCalculations.java
parentcd6a9243c056710794549a1ab5d51fbdd082ce2e (diff)
downloadzadania-fc4d96a9e3e20f8ddf035c16fc32b1effb75481b.tar.gz
Complete all Java assignments
Diffstat (limited to 'java/code/AbstractShapeCalculations.java')
-rw-r--r--java/code/AbstractShapeCalculations.java82
1 files changed, 41 insertions, 41 deletions
diff --git a/java/code/AbstractShapeCalculations.java b/java/code/AbstractShapeCalculations.java
index 3f18c0c..2b13279 100644
--- a/java/code/AbstractShapeCalculations.java
+++ b/java/code/AbstractShapeCalculations.java
@@ -2,54 +2,54 @@ import java.util.Scanner;
 import java.util.InputMismatchException;
 
 abstract class Shape {
-	abstract double area();
-	abstract void display();
+    abstract double area();
+    abstract void display();
 }
 
 class Rectangle extends Shape {
-	double length, width;
-	Rectangle(double len, double wid) {
-		length = len;
-		width = wid;
-	}
-	double area() {
-		return length * width;
-	}
-	void display() {
-		System.out.println("A rectangle with length " + length + " units and width " + width + " units has the area of " + area() + " square units.");
-	}
+    double length, width;
+    Rectangle(double len, double wid) {
+        length = len;
+        width = wid;
+    }
+    double area() {
+        return length * width;
+    }
+    void display() {
+        System.out.println("A rectangle with length " + length + " units and width " + width + " units has the area of " + area() + " square units.");
+    }
 }
 
 class Circle extends Shape {
-	double radius;
-	Circle(double r) {
-		radius = r;
-	}
-	double area() {
-		return Math.PI * radius * radius;
-	}
-	void display() {
-		System.out.println("A circle with radius " + radius + " units has the area of " + area() + " square units.");
-	}
+    double radius;
+    Circle(double r) {
+        radius = r;
+    }
+    double area() {
+        return Math.PI * radius * radius;
+    }
+    void display() {
+        System.out.println("A circle with radius " + radius + " units has the area of " + area() + " square units.");
+    }
 }
 
 class Triangle extends Shape {
-	double a, b, c;
-	Triangle(double s1, double s2, double s3) {
-		a = s1;
-		b = s2;
-		c = s3;
-	}
-	double perimeter() {
-		return a + b + c;
-	}
-	double area() {
-		var s = perimeter() / 2.0;
-		return Math.sqrt(s * (s - a) * (s - b) * (s - c));
-	}
-	void display() {
-		System.out.println("A triangle with side lengths " + a + " units, " + b + "units and " + c + " units has the area of " + area() + " square units.");
-	}
+    double a, b, c;
+    Triangle(double s1, double s2, double s3) {
+        a = s1;
+        b = s2;
+        c = s3;
+    }
+    double perimeter() {
+        return a + b + c;
+    }
+    double area() {
+        var s = perimeter() / 2.0;
+        return Math.sqrt(s * (s - a) * (s - b) * (s - c));
+    }
+    void display() {
+        System.out.println("A triangle with side lengths " + a + " units, " + b + " units and " + c + " units has the area of " + area() + " square units.");
+    }
 }
 
 class AbstractShapeCalculations {
@@ -65,12 +65,12 @@ class AbstractShapeCalculations {
             Shape s;
             s = new Rectangle(length, width);
             s.display();
-            System.out.println("Circle");
+            System.out.println("\nCircle");
             System.out.print("  Enter radius: ");
             double radius = sc.nextDouble();
             s = new Circle(radius);
             s.display();
-            System.out.println("Triangle");
+            System.out.println("\nTriangle");
             System.out.print("  Enter three side lengths: ");
             double a = sc.nextDouble(), b = sc.nextDouble(), c = sc.nextDouble();
             s = new Triangle(a, b, c);