PackageMianxiangduixiang;//trapezoidal Public classLadder {DoubleShangdi; DoubleXiadi; DoubleGao; DoubleMianji; DoubleZhouchang; Ladder (DoubleShangdi,DoubleXiadi,DoubleGao) {//using parameters to initialize properties//Resolve Parameter name duplicate this represents the current class This. Shangdi =Shangdi; This. Xiadi =Xiadi; This. Gao =Gao; } //method naming: verb + name; The first letter of a verb is lowercase//If you need a return value, simply precede the method with the type of the return value//Calculate Area DoubleGetmianji () {Mianji= (Shangdi+xiadi) *GAO/2; System.out.println ("area =" + This. Mianji); //Return Statement//Return statement required when return value is required return This. Mianji; } DoubleGetzhouchang () {//The formula is inaccurate do not refer tozhouchang= (Shangdi+xiadi) * *; System.out.println ("Perimeter =" + This. Zhouchang); //Return Statement//Return statement required when return value is required return This. Mianji; } //Mian method for testing Public Static voidMain (string[] args) {ladder La=NewLadder (5,8,3); La.getmianji (); La.getzhouchang (); } }
The area and perimeter of trapezoid in Java exercises