Advertisement
Niloy007

Untitled

Aug 14th, 2020
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.59 KB | None | 0 0
  1. class Triangle {
  2.     String color;
  3.     int height, base;
  4.  
  5.     Triangle(String color, int height, int base) {
  6.         this.color = color;
  7.         this.height = height;
  8.         this.base = base;
  9.     }
  10.  
  11.     public void getArea() {
  12.         System.out.println("The area of this " + color + " triangle is : " + (height * base) / 2.0);
  13.     }
  14. }
  15.  
  16.  
  17.  
  18. public class Test {
  19.     public static void main(String[] args) {
  20.         Triangle triangle = new Triangle("Black", 3, 2);
  21.         triangle.getArea();
  22.         Triangle triangle1 = new Triangle("Green", 5, 6);
  23.         triangle1.getArea();
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement