Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Triangle {
- String color;
- int height, base;
- Triangle(String color, int height, int base) {
- this.color = color;
- this.height = height;
- this.base = base;
- }
- public void getArea() {
- System.out.println("The area of this " + color + " triangle is : " + (height * base) / 2.0);
- }
- }
- public class Test {
- public static void main(String[] args) {
- Triangle triangle = new Triangle("Black", 3, 2);
- triangle.getArea();
- Triangle triangle1 = new Triangle("Green", 5, 6);
- triangle1.getArea();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement