class DvouDObrazec { //-hierarchie trid private double width; private double height; DvouDObrazec() { width = height = 0.0; } DvouDObrazec(double w, double h) { width = w; height = h; } DvouDObrazec(double x) { width = height = x; } double getWidth() { return width; } double getHeight() { return height; } void setWidth(double w) { width = w; } void setHeight(double h) { height = h; } void showDim() { System.out.println("sirka a vyska jsou " + width + " a " + height); } } class Trojuhelnik extends DvouDObrazec { private String style; Trojuhelnik() { super(); style = ""; } Trojuhelnik(String s, double w, double h) { super(w, h); style = s; } Trojuhelnik(double x) { super(x); style = "stejne vysoky jako siroky"; } double area() { return getWidth() * getHeight() / 2; } void showStyle() { System.out.println("Trojuhelnik je " + style); } } class BarevnyTrojuhelnik extends Trojuhelnik { private String barva; BarevnyTrojuhelnik(String c, String s, double w, double h) { super(s, w, h); barva = c; } String getBarva() { return barva; } void showBarva() { System.out.println("barva je " + barva); } } class ObrazceHierar { public static void main(String args[]) { BarevnyTrojuhelnik t1 = new BarevnyTrojuhelnik("zluty", "placaty", 20.0, 2.0); BarevnyTrojuhelnik t2 = new BarevnyTrojuhelnik("zeleny", "vysoky", 2.0, 12.0); System.out.println("informace pro t1: "); t1.showStyle(); t1.showDim(); t1.showBarva(); System.out.println("Plocha = " + t1.area()); System.out.println(); System.out.println("informace pro t2: "); t2.showStyle(); t2.showDim(); t2.showBarva(); System.out.println("Plocha = " + t2.area()); } }