This is a practice project for learning Java basics. You'll simulate a robot doing something during a match using variables, loops, and conditionals.
This is a console application - it runs in your terminal and prints text output. No robot framework needed! This helps you learn Java fundamentals before working with real robot code.
- Variables (int, double, String, boolean)
- For loops (to simulate time passing)
- If statements (to make decisions)
- Print statements (to show what's happening)
- Basic program structure
Open RobotSim.java and complete these TODOs:
Add variables to track robot information. Ideas:
int batteryLevel = 100; // Battery starts at 100%
double distanceTraveled = 0.0; // Distance in feet
int gamePiecesCollected = 0; // Number of game pieces
String robotState = "IDLE"; // Current state
int matchTime = 15; // 15 second autonomous periodUse a for loop to simulate time passing (e.g., 15 seconds for autonomous period):
for (int second = 0; second <= 15; second++) {
System.out.println("Time: " + second + "s");
// Your simulation logic here
}Make things happen! Ideas:
- Battery drains over time:
batteryLevel -= 2; - Robot moves:
distanceTraveled += 3.5; - Collect game pieces at certain times
- Change robot state based on conditions
- Print updates each second
Make decisions based on conditions:
if (batteryLevel < 20) {
System.out.println("⚠️ WARNING: Low battery!");
}
if (second == 5) {
robotState = "SCORING";
gamePiecesCollected++;
}Add a Scanner to get user input for robot actions:
Scanner scanner = new Scanner(System.in);
System.out.println("Enter action (move, score, stop): ");
String action = scanner.nextLine();After the loop, show the results:
System.out.println("Final Battery: " + batteryLevel + "%");
System.out.println("Distance Traveled: " + distanceTraveled + " feet");
System.out.println("Game Pieces Scored: " + gamePiecesCollected);javac RobotSim.javajava RobotSimHere are some creative ideas for your simulation:
- Simulate a 15-second autonomous period
- Robot starts IDLE, then MOVES to scoring position
- Scores game pieces at specific times
- Battery drains as robot operates
- Print position updates
- Start with 100% battery
- Different actions drain different amounts (moving = 2%, scoring = 5%)
- If battery < 20%, print warning
- If battery reaches 0, robot stops
- Track distance traveled in feet
- Robot moves at 3.5 feet per second
- Print position updates
- Calculate if robot reached target distance
- Robot collects game pieces at certain times
- Each piece takes 2 seconds to collect
- Track total pieces collected
- Print when each piece is scored
Create different robot states:
- IDLE → MOVING → COLLECTING → SCORING → RETURNING → IDLE
- Change states based on time or conditions
- Print state changes
Here's what your simulation might look like:
=== Robot Simulation Started ===
Time: 0s
Robot State: IDLE
Battery: 100%
Time: 1s
Robot State: MOVING
Battery: 98%
Distance: 3.5 feet
Time: 2s
Robot State: MOVING
Battery: 96%
Distance: 7.0 feet
Time: 5s
Robot State: SCORING
Battery: 90%
Game piece collected! Total: 1
...
=== Simulation Complete ===
Final Battery: 70%
Distance Traveled: 52.5 feet
Game Pieces Scored: 3
CONTACT A LEAD
After completing this project, you can:
- Add more complex logic (random events, sensor simulation)
- Create multiple robot "modes"
- Simulate a full 2.5 minute match (not just autonomous)
- Add user input to control the robot
- Create multiple classes (Robot, GamePiece, Field, etc.)