Smart猫小萌
123456789101112131415package com.test;public class TestTrapezia { public static void main(String[] args){ Trapezia tr1=new Trapezia(); Trapezia tr2=new Trapezia(); tr1.setA(3); tr1.setB(5); tr1.setH(6); System.out.println("tr1的面积为:"+tr1.getArea()); tr2.setA(2.3f); tr2.setB(3.1f); tr2.setH(4.4f); System.out.println("tr2的面积为:"+tr2.getArea()); }} 1234567891011121314151617181920212223242526272829303132package com.test;public class Trapezia { float a; float b; float h; public Trapezia(){ a=1f; b=1f; h=1f; } public float getA() { return a; } public void setA(float a) { this.a = a; } public float getB() { return b; } public void setB(float b) { this.b = b; } public float getH() { return h; } public void setH(float h) { this.h = h; } public float getArea(){ return (a+b)*h/2; }运行结果为:12tr1的面积为:24.0tr2的面积为:11.879999