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

📄 exercise9_7.java

📁 Introduction to java programming 一书中所有编程练习部分的源码
💻 JAVA
字号:
public class Exercise9_7 {  public static void main(String[] args) {    Octagon a1 = new Octagon(5);    System.out.println("Area is " + a1.findArea());    System.out.println("Perimeter is " + a1.findPerimeter());        Object a2 = a1.clone();    System.out.println("Compare the methods " + a1.compareTo(a2));        System.out.println(a1.hashCode());    System.out.println(a2.hashCode());    System.out.println(a1);    System.out.println(a2);  }}class Octagon extends GeometricObject   implements Comparable, Cloneable {  private double side;  /** Construct a Octagon with the specified side */  public Octagon (double side) {    // Implement it    this.side = side;  }  /** Implement the abstract method findArea in      GeometricObject */  public double findArea() {     // Implement it    return (2 + 4 / Math.sqrt(2)) * side * side;  }  /** Implement the abstract method findPerimeter in      GeometricObject */  public double findPerimeter() {    // Implement it    return 8 * side;  }  /** Implement the compareTo method in      the Comparable interface to  */  public int compareTo(Object obj) {    // Implement it (compare two Octagons based on their areas)    double thisArea = this.findArea();    double otherArea = ((Octagon)obj).findArea();        if (thisArea > otherArea)       return 1;    else if (thisArea == otherArea)      return 0;    else       return -1;  }  /** Implement the clone method in      the Object class */  public Object clone() {    // Implement it     try {      return super.clone();    }    catch (CloneNotSupportedException ex) {      return null;    }      }}

⌨️ 快捷键说明

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