1 Star 1 Fork 0

CS-IMIS-23/20172313yukunpeng

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Coin.java 1.07 KB
一键复制 编辑 原始数据 按行查看 历史
package srcNo7;
public class Coin {
private final int HEADS = 0;
private final int TAILS = 1;
protected int face;
//-------------------------------------------------------------
// Sets up the coin by flipping it initially.
//-------------------------------------------------------------
public Coin() {
flip();
}
public void flip() {
face = (int) (Math.random() * 2);
}
//-------------------------------------------------------------
// Returns true if the current face of the coin is heads.
//-------------------------------------------------------------
public boolean isHeads() {
return (face == HEADS);
}
//-------------------------------------------------------------
// Returns the current face of the coin as a string.
//-------------------------------------------------------------
public String toString() {
String faceName;
if (face == HEADS)
faceName = "Heads";
else
faceName = "Tails";
return faceName;
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/CS-IMIS-23/20172313yukunpeng.git
git@gitee.com:CS-IMIS-23/20172313yukunpeng.git
CS-IMIS-23
20172313yukunpeng
20172313yukunpeng
master

搜索帮助