⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 demoofsimplefigure.java

📁 提供了常用的JAVA技术的示例
💻 JAVA
字号:
/* 例5-23  用接口改造 例5-22   增加 area() 增加了四个返回值,将其显示出来。 问题:  如果不用接口定义 Area(),程序也可以实现!        坐标量有什么作用??  去掉也可以吗?*/package DemoOfSimpleFigure;import javax.swing.UIManager;import java.awt.*;interface Shape{    int position_x=50,position_y=50;  // 坐标量有什么作用??    double PI=3.1415926;    //void draw();}interface Area extends Shape{    //double area();}class Square implements Shape,Area{    private int length;    void setSize(int l){        length=l;    }    int give(){        return length;    }    public void draw(){        System.out.print("this is a square.");    }    public double area(){        return length*length;    }}class Circle implements Shape,Area{    private int radius;    void setSize(int r){        radius=r;    }    int give(){        return radius;    }    public void draw(){        System.out.print("this is a circle.");    }    public double area(){        return PI*radius*radius;    }}class Trigon implements Shape,Area{    private int bottom;    private int highness;    void setSize(int b,int h){        bottom=b;        highness=h;    }    int give1(){        return bottom;    }    int give2(){        return highness;    }    public void draw(){        System.out.print("this is a Trigon.");    }    public double area(){        return 0.5*bottom*highness;    }}public class DemoOfSimpleFigure {    public static void main(String[] args) {        Square sq=new Square();        Circle ci=new Circle();        Trigon tr=new Trigon();        sq.draw();        sq.setSize(5);        System.out.print("  length="+sq.give()+"  Area="+sq.area()+"\n");        ci.draw();        ci.setSize(2);        System.out.print("  radius="+ci.give()+"  Area="+ci.area()+"\n");        tr.draw();        tr.setSize(4,3);        System.out.print("  bottom="+tr.give1()+"  highness="+tr.give2()+"  Area="+tr.area());  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -