【Java开源代码栏目提醒】:以下是网学会员为您推荐的Java开源代码-BoBingDemo.java,希望本篇文章对您学习有所帮助。
// 引入util包包含Random类,引入test包包含NumberFormat类
import java.util.*;
import java.text.NumberFormat;
// User类
class User {
// phoneNum存储手机号码,name存储用户,idCardNum存储
// 身份证号码,region存储用户所在区域
protected String phoneNum, name, idCardNum, region;
// inNetMonth存储用户入网时间,phonePoint存储用户积分
protected int inNetMonth, phonePoint;
// phoneCost存储用户手机话费
protected float phoneCost;
// 构造器
User(String phoneNum, String name, String idCardNum, String region,
int inNetMonth, float phoneCost, int phonePoint) {
this.phoneNum = phoneNum;
this.name = name;
this.idCardNum = idCardNum;
this.region = region;
this.inNetMonth = inNetMonth;
this.phoneCost = phoneCost;
this.phonePoint = phonePoint;
}
// 查询手机话费
float queryCost() {
// 指定数字格式
NumberFormat nfLocal = NumberFormat.getNumberInstance();
// 指定输出的小数点的位数
nfLocal.setMaximumFractionDigits(2);
System.out.println("您当前的话费是" + nfLocal.format(phoneCost) + "元");
return phoneCost;
}
// 查询手机积分
int queryPoint() {
System.out.println("您当前可用积分是" + phonePoint + "元");
return phonePoint;
}
}
// BoBingUser类
class BoBingUser extends User {
// diceNum数组存储每种点数出现的次数
int[] diceNum;
// 随机类的对象
Random rnd;
// 存储游戏积分
int gamePoint;
// 构造器
BoBingUser(String phoneNum, String name, String idCardNum, String region,
int inNetMonth, float phoneCost, int phonePoint) {
super(phoneNum, name, idCardNum, region, inNetMonth, phoneCost, phonePoint);
diceNum = new int[7];
rnd = new Random();
gamePoint = 0;
}
// 模拟掷骰子的过程
void throwDice() {
int i, num;
// 清空数组
for (i = 1; i <= 6; i++) {
diceNum[i] = 0;
}
// 掷6次骰子
for (i = 1; i <= 6; i++) {
// 生成1~6的随机数
num = rnd.nextInt(6) + 1;
// 记录本次掷的骰子点数
diceNum[num]++;
}
}
// 博饼的过程
String BoBing(int flag) {
String s;
// 掷骰子
throwDice();
// 6个4,红六勃
if (diceNum[4] == 6) {
// flag为1,使用双倍积分卡
if (flag == 1) {
// 增加双倍积分
gamePoint = gamePoint + 200;
// 通讯费0.1元,资讯费0.1元,双倍积分卡0.5元,共0.7元
phoneCost = phoneCost + 0.70f;
s = "您太有先见之名红六勃!加上双倍积分卡!共送您200分!";
return s;
}
else {
gamePoint = gamePoint + 100;
phoneCost = phoneCost + 0.20f;
s = "噢!额滴神啊!红六勃!I输了u,I服了u,送您100分!";
return s;
}
}
// 黑六勃
if (diceNum[6] == 6) {
// 使用护身卡
if (flag == 2) {
// / 通讯费0.1元,资讯费0.1元,双倍积分卡0.5元,共0.7元
phoneCost = phoneCost + 0.70f;
s = "黑六勃啊!不过玉皇大帝来信息了,说谁都不能动您,这次就不扣分了!";
return s;
}
else {
// 未使用护身卡扣100分
gamePoint = gamePoint - 100;
phoneCost = phoneCost + 0.20f;
s = "您真是背啊,一黑到底,扣100分,赶紧烧香拜佛吧!";
return s;
}
}
// 状元
if (diceNum[1] == 6 || diceNum[2] == 6 || diceNum[3] == 6
|| diceNum[5] == 6) {
if (flag == 1) {
phoneCost = phoneCost + 0.70f;
gamePoint = gamePoint + 100;
s = "状元及第又好事成双,送上100分!";
return s;
}
else {
phoneCost = phoneCost + 0.20f;
gamePoint = gamePoint + 100;
s = "状元及第!您真是鸿运当头!奖励50分!";
return s;
}
}
// 状元插金花
if (diceNum[4] == 4 && diceNum[2] == 2) {
if (flag == 1) {
phoneCost = phoneCost + 0.70f;
gamePoint = gamePoint + 90;
s = "状元插金花,好事成双来!送上90分!";
return s;
}
else {
phoneCost = phoneCost + 0.20f;
gamePoint = gamePoint + 100;
s = "好手气!状元插金花!45分是你的了!";
return s;
}
}
// 五子登科
if (diceNum[1] == 5 || diceNum[2] == 5 || diceNum[3] == 5 ||
diceNum[4] == 5 || diceNum[5] == 5 || diceNum[6] == 5) {
if (flag == 1) {
phoneCost = phoneCost + 0.70f;
gamePoint = gamePoint + 80;
s = "五子登科!双倍积分卡用对了啊!送您80分!";
return s;
}
else {
phoneCost = phoneCost + 0.20f;
gamePoint = gamePoint + 40;
s = "五子登科!家族兴旺啊!40分拿去!";
return s;
}
}
// 状元
if (diceNum[4] == 4) {
if (flag == 1) {
phoneCost = phoneCost + 0.70f;
gamePoint = gamePoint + 70;
s = "状元!您真是学识渊博,双倍记分卡用的正是时候,70分到手咯!";
return s;
}
else {
phoneCost = phoneCost + 0.20f;
gamePoint = gamePoint + 35;
s = "状元!您真是学富五车,才高八斗啊!奖励35分!";
return s;
}
}
// 对堂
if (diceNum[1] == 1 && diceNum[2] == 1 && diceNum[3] == 1 &&
diceNum[4] == 1 && diceNum[5] == 1 &