【Java开源代码栏目提醒】:网学会员鉴于大家对Java开源代码十分关注,论文会员在此为大家搜集整理了“BlueBean.java”一文,供大家参考学习
package ch9;
import java.util.*;
public class BlueBean
{
int blueColor,guess=0,lower=0,higher=255;
boolean success;
String hintMsg;
public BlueBean()
{
initAnswer();
}
//产生随机整数
public synchronized void initAnswer()
{
blueColor=(int)(Math.random()*256);
lower=0;
higher=255;
hintMsg="0-255";
success=false;
}
public int getBlueColor()
{
return blueColor;
}
public void setGuess(String myGuess)
{
int intGuess;
try
{
intGuess=Integer.parseInt(myGuess);
}
catch(NumberFormatException e)
{
intGuess= -1;
}
if(intGuess==blueColor)
success=true;
else if(intGuess== -1)
hintMsg="请输入一个整数!";
else if(intGuess<blueColor)
{
lower= intGuess;
hintMsg=" "+lower+" - "+higher+" ";
}
else if(intGuess>blueColor)
{
higher= intGuess;
hintMsg=" "+lower+" - "+higher+" ";
}
guess= intGuess;
}
public int getGuess()
{
return guess;
}
public Boolean getSuccess()
{
return success;
}
public String getHintMsg()
{
return " "+hintMsg;
}
}