Skip to content

Conversation

@lth-1026
Copy link

No description provided.

Add Car class
- Implemented private fields (#name, #totalDistance)
- Added getter methods for encapsulated access
- Implemented showDistance() method
- Created unit tests for Car class
Add input validation for car name entry
- Added empty input check to prevent blank values
- Applied regex /^([^,]{1,5})(,([^,]{1,5}))*$/ to ensure each name is 1–5 chars
Changed structure to include a Race object
to better represent relationships between objects in the program
- Integrated getInput logic directly into registerCars
- Simplified structure by removing the private getInput method
- Added splitInput function that splits input string by comma
- Throws an error if any of the split results is an empty
- Added registerCars method to handle car name registration
- Reads input from console using getInput()
- Splits input by comma and validates for empty or duplicate names
- Stores validated car names in #cars property
- Added maxStop property initialized in constructor
- Implemented setStop method to receive stop value from user
- Ensured stop cannot exceed maxStop
- Modified registerCars to instantiate Car objects instead of storing name strings
- Each car is now created via the Car class during registration
- Improved data consistency and encapsulation within the Race class
- Added forwardAttepmt method to attempt car movement
- Calls isPossibleForward() to check if the car can move
- Executes forward() when movement condition is met
- Implemented start() to initiate the race process
- Uses runRound() to perform each round of car movements
- Calls showRoundResult() to display each round's result
- Implemented showWinner() to display the final winner(s) of the race
- Calls findMaxDistance() to determine the highest total distance
- Uses getWinners() to retrieve cars matching the maximum distance
- Prints the winner names in formatted output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant