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

📄 die.java

📁 java版的数据结构的完全代码 免费提供了 学习数据结构的请下载
💻 JAVA
字号:
// Introduced in Chapter 1/** A six-sided die for use in games. */public class Die implements Comparable<Die> {  /** The face of this Die that is showing. */  private int topFace;  /** Initialize the top face to 1. */  public Die() {    this.topFace = 1;  }  // Added in Chapter 8  public int compareTo(Die that) {    return topFace - that.topFace;  }    // Added in Chapter 2  /** Return true if that Die has the same top face as this one. */  public boolean equals(Object that) {    if (this == that) {      return true;    }    if (that == null) {      return false;    }    if (getClass() != that.getClass()) {      return false;    }    Die thatDie = (Die)that;    return topFace == thatDie.topFace;  }  /** Return the top face of this Die. */  public int getTopFace() {    return this.topFace;  }  /**   * Set the top face to a random integer between 1 and 6, inclusive.   */  public void roll() {    this.topFace = ((int)(Math.random() * 6)) + 1;  }  /** Set the top face to the specified value. */  public void setTopFace(int topFace) {    this.topFace = topFace;  }  public String toString() {    return "" + this.topFace;  }    /** Create a Die, print it, roll it, and print it again. */  public static void main(String[] args) {    Die d = new Die();    System.out.println("Before rolling: " + d);    d.roll();    System.out.println("After rolling: " + d);  }}

⌨️ 快捷键说明

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