summary refs log tree commit diff stats
path: root/java/code/CuboidCalculations.java
blob: b9c478f9725ee7572a631b65841be56fd7c6881d (plain) (blame)
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
class Rectangle {
    int length;
    int breadth;

    Rectangle(int length, int breadth) {
        this.length = length;
        this.breadth = breadth;
    }

    int area() {
        return length * breadth;
    }
}

class Cuboid extends Rectangle {
    int height;

    Cuboid(int length, int breadth, int height) {
        super(length, breadth);
        this.height = height;
    }

    int surfaceArea() {
        return 2 * (area() + (length + breadth) * height);
    }

    int volume() {
        return area() * height;
    }
}

public class CuboidCalculations {
    public static void main(String[] args) {
        Cuboid cuboid = new Cuboid(5, 4, 3);

        System.out.println("Surface area of the Cuboid: " + cuboid.surfaceArea());
        System.out.println("Volume of the Cuboid: " + cuboid.volume());
    }
}