Skip to content

Instantly share code, notes, and snippets.

Created October 16, 2014 13:18
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Mars Rover kata solution
package com.technologyconversations.kata.marsrover;
Method receiveCommands should be used to transmit commands to the rover.
public class Rover {
private Coordinates coordinates;
public void setCoordinates(Coordinates value) {
coordinates = value;
public Coordinates getCoordinates() {
return coordinates;
public Rover(Coordinates coordinatesValue) {
public void receiveCommands(String commands) throws Exception {
for (char command : commands.toCharArray()) {
if (!receiveSingleCommand(command)) {
public boolean receiveSingleCommand(char command) throws Exception {
switch(Character.toUpperCase(command)) {
case 'F':
return getCoordinates().moveForward();
case 'B':
return getCoordinates().moveBackward();
case 'L':
return true;
case 'R':
return true;
throw new Exception("Command " + command + " is unknown.");
public String getPosition() {
return getCoordinates().toString();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment