📄 Spec Sheet
Project Name: PX_GuessTheNumber_lastname.java
Description:
Create a console-based Java game where the computer selects a random number and the player attempts to guess it within a limited number of tries.
Learning Targets
- Scanner input
- Loops and conditionals
- Methods and decomposition
- Random number generation
- Input validation
Game Rules
- Random number between 1 and 100
- Player has 7 attempts
- Feedback: Too High / Too Low / Correct
- Replay option
Requirements
- Use at least 3 methods
- Use loops (no hardcoding)
- Validate input
- Include extensive comments
🧠 Pseudocode
START
Display welcome message
DO
generate random number
set attempts to zero
WHILE attempts < max AND not won
prompt user for guess
validate input
increment attempts
IF guess correct
show win message
ELSE IF guess low
show too low
ELSE
show too high
END WHILE
IF not won
reveal answer
ask play again
WHILE yes
END
💻 Java Program (Extensively Commented)
import java.util.Random;
import java.util.Scanner;
public class PX_GuessTheNumber_lastname {
insert code here *****************************************************
// Input validation method
public static int getValidInteger(String prompt, int min, int max){
while(true){
System.out.print(prompt);
String line = scanner.nextLine();
try{
int value = Integer.parseInt(line);
if(value >= min && value <= max){
return value;
}
else{
System.out.println("Number must be between " + min + " and " + max);
}
}
catch(NumberFormatException e){
System.out.println("Invalid input.");
}
}
}
}
📊 Rubric (100 Points)
| Category | Points | Criteria |
|---|---|---|
| Program Compiles | 10 | No errors when running |
| Game Logic | 20 | Random number, attempts, win/lose correct |
| Loops | 15 | Uses loops correctly |
| Methods | 15 | Uses multiple methods |
| Input Validation | 15 | Program does not crash |
| Output Formatting | 10 | Clear readable output |
| Comments | 10 | Extensive comments included |
| Style | 5 | Proper naming and formatting |
📁 Google Classroom Submission Files
- PX_GuessTheNumber_lastname.java — Java source code
- PX_GuessTheNumber_lastname.png — Screenshot showing program running
- PX_GuessTheNumber_lastname.mp4 — Video of the program running