Generation

generate functionMon, 10 Jul 2023

(2) 以下の指示に従って、Trapezoid_k クラスをベースに Trapezoid_o クラスを作成せよ ・ Figure_k クラスを継承し、さらに Resize_o インターフェースを実装する ・ Resize_o インターフェースの makeHalf メソッドをオーバライドし、フィールドの height の長さを 1/2 に変化させる処理を書く

class Trapezoid_k { private double height; private double top; private double bottom; public Trapezoid_k(double height, double top, double bottom) { this.height = height; this.top = top; this.bottom = bottom; } public double area() { return (this.top + this.bottom) * this.height / 2.0; } } interface Resize_o { public void makeHalf(); } class Trapezoid_o extends Trapezoid_k implements Resize_o { public Trapezoid_o(double height, double top, double bottom) { super(height, top, bottom); } public void makeHalf() { this.height /= 2; } }

Questions about programming?Chat with your personal AI assistant