| PSP2.1 | Personal Software Process Stages | 预估耗时(分钟) | 实际耗时(分钟) |
|---|---|---|---|
| Planning | 计划 | 10 | 10 |
| Development | 开发 | 120 | 140 |
| Reporting | 报告 | 30 | 20 |
| Total | 合计 | 160 | 170 |
二、开发环境
-
操作系统:64-bit Windows 10
-
使用语言:Java
-
JDK版本:jdk-16.0.1
-
IDE:IntelliJ IDEA 2023.2.2
三、基本原理
项目内容
输入石头剪刀布的英文单词的字母开头大写,即会进行你和电脑的石头剪刀布
四、计算模块接口设计与实现过程

五、计算模块部分单元测试展示
import java.util.Random;
import java.util.Scanner;
public class RockPaperScissors {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Random random = new Random();
String[] choices = { "rock", "paper", "scissors" };
System.out.println("Welcome to the Rock-Paper-Scissors game!");
System.out.println("Enter your choice (rock[R], paper[P], or scissors[S]): ");
String playerChoice = scanner.nextLine().toUpperCase();
if (playerChoice.equals("R") || playerChoice.equals("P") || playerChoice.equals("S")) {
String[] abbreviations = { "R", "P", "S" };
int randomIndex = random.nextInt(choices.length);
int playerChoiceIndex = -1;
for (int i = 0; i < abbreviations.length; i++) {
if (playerChoice.equals(abbreviations[i])) {
playerChoiceIndex = i;
break;
}
}
if (playerChoiceIndex != -1) {
String computerChoice = choices[randomIndex];
System.out.println("Computer choice: " + computerChoice);
System.out.println("Your choice: " + choices[playerChoiceIndex]);
if (choices[playerChoiceIndex].equals(computerChoice)) {
System.out.println("It's a tie!");
} else if ((choices[playerChoiceIndex].equals("rock") && computerChoice.equals("scissors"))
|| (choices[playerChoiceIndex].equals("paper") && computerChoice.equals("rock"))
|| (choices[playerChoiceIndex].equals("scissors") && computerChoice.equals("paper"))) {
System.out.println("You win!");
} else {
System.out.println("Computer wins!");
}
} else {
System.out.println("Invalid choice. Please enter R (rock), P (paper), or S (scissors).");
}
} else {
System.out.println("Invalid choice. Please enter R (rock), P (paper), or S (scissors).");
}
scanner.close();
}
}
六、测试

| 玩家输入 | 随机数生成的结果 | 预期结果 | |
|---|---|---|---|
| 1 | R | 0 (rock) | It's a tie! |
| 2 | P | 1 (paper) | It's a tie! |
| 3 | S | 2 (scissors) | It's a tie! |
| 4 | R | 1 (paper) | Computer wins! |
| 5 | P | 2 (scissors) | Computer wins! |
| 6 | S | 0 (rock) | Computer wins! |
| 7 | R | 2 (scissors) | You win! |
| 8 | P | 0 (rock) | You win! |
| 9 | S | 1 (paper) | You win! |
| 10 | A | - | Invalid choice. Please enter R (rock), P (paper), or S (scissors). |