[size=12px][size=11px]编写一个简单的JAVA Applet应用程序,
1:创建一个类Rectangle,添加属性长weidth、宽heigth。
2:在Rectangle中添加两个方法,计算矩形的周长与面积。
3:再创建一个Applet子类作为主类AP1,在类体中调用类Rectangle的方法计算长=20、宽=10的矩形周长与面积并输出请各位好心人帮帮忙!!帮我解答这三题!!急需~~谢谢了  

解决方案 »

  1.   

    import java.applet.Applet;
    import java.awt.Graphics;class Rectangle{
    double weidth;
    double height;

    public Rectangle(double weidth, double height) {
    this.weidth = weidth;
    this.height = height;
    }
    public double Zhouchang(){
    return 2*(weidth+height);
    }
    public double Mianji(){
    return weidth*height;
    }
    }
    public class AP1 extends Applet {
    Rectangle a=new Rectangle(20,10);
    public void paint(Graphics g) {
    g.drawString("周长是"+a.Zhouchang()+"   面积是"+a.Mianji(),20,50);
    }

    }