-1
- 我有使用随机类中包
java.util
,以产生一个数字来创建程序1和100 - 之间的用户已经被给予6次试图猜测的数的最大如果他们在第6次尝试中未能正确猜测,则应显示目标号码。该计划需要向反馈用户提供指示他们的猜测是否过高或过低。如果猜测是正确的,程序会说“恭喜,你的猜测是正确的。”
- 用户应该在开始会话时提供他们的名字,这应该被存储并用于随后的记录生成。
- 程序应该为用户创建一个会话,并且应该允许他们在该会话中拥有尽可能多的内容。在每一个程序中,程序都应该生成一个新的随机数,并为用户提供多达6次的猜测。当目标号码被正确猜测或试图做出6次尝试时,应该让用户选择退出或进行其他游戏/去。
这是我到目前为止有:猜测游戏的Java JCreator的
import java.util.Random;
import javax.swing.JOptionPane;
public class GuessANumber3 {
public static int TARGET = 0;
public static void main(String[] args) {
Random R = new Random();
TARGET = R.nextInt(100);
String guessString;
int guess;
int count = 0;
int bestScore = 0;
System.out.println(TARGET);
do {
// read in a number from user as a string
guessString = JOptionPane.showInputDialog("Enter first integer");
// convert number from type String to type int
guess = Integer.parseInt(guessString);
count++;
if (guess > TARGET) {
JOptionPane.showMessageDialog(null, "Your guess is too high", "Hint",
JOptionPane.PLAIN_MESSAGE);
} else {
if (guess < TARGET) {
JOptionPane.showMessageDialog(null, "Your guess is too low", "Hint",
JOptionPane.PLAIN_MESSAGE);
}
}
System.out.println(count);
if (count == 6)
break;
} while (guess != TARGET);
if (guess == TARGET)
JOptionPane.showMessageDialog(null, "You found it with " + count + "guesses.",
"Congratulations!", JOptionPane.PLAIN_MESSAGE);
else
JOptionPane.showMessageDialog(null, "You have reached the maximum attempts in this go",
"Attention", JOptionPane.PLAIN_MESSAGE);
if (count < bestScore)
bestScore = count;
}
}
谁能帮我部分3和4?
你有具体问题是否在3和4? – Tom
不需要存储姓名的原因是,当用户希望终止他们的会话时,他们的表演可以被写入记录文件。 –