📄 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;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -