Thinking in JAVA第四版源代码

源代码在线查看: input.java

软件大小: 543 K
上传用户: wanglp094
关键词: Thinking JAVA in 源代码
下载地址: 免注册下载 普通下载 VIP

相关代码

				//: enumerated/Input.java
				package enumerated;
				import java.util.*;
				
				public enum Input {
				  NICKEL(5), DIME(10), QUARTER(25), DOLLAR(100),
				  TOOTHPASTE(200), CHIPS(75), SODA(100), SOAP(50),
				  ABORT_TRANSACTION {
				    public int amount() { // Disallow
				      throw new RuntimeException("ABORT.amount()");
				    }
				  },
				  STOP { // This must be the last instance.
				    public int amount() { // Disallow
				      throw new RuntimeException("SHUT_DOWN.amount()");
				    }
				  };	
				  int value; // In cents
				  Input(int value) { this.value = value; }
				  Input() {}
				  int amount() { return value; }; // In cents
				  static Random rand = new Random(47);
				  public static Input randomSelection() {
				    // Don't include STOP:
				    return values()[rand.nextInt(values().length - 1)];
				  }
				} ///:~
							

相关资源