java 第五周实验【报告2】

2.封装一类梯形对象Ladder,该类对象具有上底、下底和高的属性,具有初始化梯形的功能、修改上底、下底和高的功能、求周长的功能、求面积的功能。

 

 

 

public class TestLadder {
	private double top;
	private double bottom;
	private double height;
		
	
	TestLadder(double top,double bottom,double height)	{
		this.top=top;
		this.bottom=bottom;
		this.height=height;	
	}
	
	TestLadder(){
		this.top =1;
		this.bottom=2;
		this.height=3;	
		
	}
	public void set_Ladder(double top,double bottom,double height){
		this.top=top;
		this.bottom=bottom;
		this.height=height;	
	}
	
	public double get_Perimeter()
	{
		return (this.bottom+this.height+this.top);
	}
	
	public double get_Area(){
		double s;
		s=(this.top+this.bottom)*height/2;
		return s;
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		TestLadder t = new TestLadder(2,4,3);
		t.get_Area();
		t.get_Perimeter();
        double x1,x2;
        x1=t.get_Area();
        x2=t.get_Perimeter();
        System.out.println(x1+"   "+x2);		
	}

}


 

你可能感兴趣的:(java 第五周实验【报告2】)