Question: In this assignment, you will practice developing UML State Machines to specify system behavior, and will practice writing code that conforms to the State Machine

In this assignment, you will practice developing UML State Machines to specify system behavior, and will practice writing code that conforms to the State Machine model. You can draw UML State Machine model by hand, or by using any software tool of your choosing.

Lunar Rover

Back in July 30th 1971, the crew of Apollo 15 reached the moon surface. The first American astronaut reached the moon along with his team. But they needed a mean of transportation. Their solution: A lunar buggy called Lunar Rover that could travel speeds up to 12 km/h. This was an awesome opportunity for astronauts to travel long distances outside Earth, but there were some technological constraints 45 years ago. The Lunar Roving Vehicle could had only two pedals and two buttons to control the vehicles systems.

Movement Control:

Engineers had to be creative in order to add all the functionality need for a lunar cruise, so they came up with the following ideas:

When the right pedal was pressed once it accelerates the buggy forward.

If accelerating forward and you press right pedal twice it deaccelerates.

To achieve constant forward speed press the right pedal for more than 5 seconds.

If the buggy is at rest and the left pedal is pressed for more than 5 seconds, it will accelerate backwards.

1. Design a state machine to model the Movement Control as described above

2.Provide an implementation for the state machine in Java

Every state should implement an entry action that prints on the console the current state.

Camera & Drill :

The coolest feature of the buggy was not its speed but rather the color television camera, the 16-mm camera, and the drill. The control was packed inside a television control unit. The only problem was that the cameras, and the lunar rover drill were also controlled by the same control unit. So again engineers used the two button controller to manipulate all devices:

Press the button 1 for five seconds to interact with the color camera.

Press the button 1 for ten seconds to interact with the 16-mm camera.

Press button 1 twice to interact with the drill.

Pressing button 2 at any of these modes return to idle state.

In any of the two camera modes, pressing button 1 takes a picture, while if pressed for 5 seconds activates the temporizer (moon selfies).

Last inside the drill mode button 1 only acted as an on off switch.

1.Design a state machine to model the Camera and Drill. Extend the model you developed for the movement control

2.Provide an implementation for this extended state machine in Java.

Every state should implement an entry action that prints on the console the current state.

This is what i have so far:

MarsRover.java

import java.util.Scanner;

public class MarsRover {

private String inst_set;

private Plateau p;

private Cell currentLocation;

public enum Direction{N,S,E,W}

Direction dir;

public MarsRover(Plateau p1, int x, int y, Direction dir, String instSet) {

p=p1;

inst_set=instSet;

this.dir=dir;

currentLocation=new Cell(x, y);

}

public MarsRover(){}

private void executeInst() {

int i = 0;

while (i < inst_set.length()) {

char inst = inst_set.charAt(i++); //get each inst separately as a character

if (inst == 'M') {

Cell nextCell = p.getNeighbour(dir, currentLocation);

if (nextCell != null)

currentLocation = nextCell;

else

System.out.println("This move is not possible. Going to next Instruction");

}

if (inst == 'L' || inst == 'R') {

dir = setDirection(dir, inst);

}

}

}

public void showCurrentLocation(){

System.out.println("Current Cell is:");

System.out.print(currentLocation.x);

System.out.print("\t"+currentLocation.y);

System.out.print("\t"+dir+" ");

}

public Direction setDirection(Direction dir, char inst) {

if(inst=='L') {

switch (dir) {

case N:

dir = Direction.W;

break;

case W:

dir = Direction.S;

break;

case S:

dir = Direction.E;

break;

case E:

dir = Direction.N;

break;

}

}

else if(inst=='R'){

switch (dir) {

case N:

dir = Direction.E;

break;

case W:

dir = Direction.N;

break;

case S:

dir = Direction.W;

break;

case E:

dir = Direction.S;

break;

}

}

return dir;

}

public static void main(String... a){

Plateau p1=new Plateau();

Scanner in = new Scanner(System.in);

int x,y;

String instSet;

String dir;

System.out.println("Enter the direction the rover is Headed");

dir=in.nextLine();

System.out.println("Enter the Initial XLocation:");

x=in.nextInt();

in.nextLine();

System.out.println("Enter the Initial YLocation:");

y=in.nextInt();

in.nextLine();

System.out.println("Enter the Instructions\t");

instSet=in.nextLine();

MarsRover mr1=new MarsRover(p1,x,y,Direction.valueOf(dir),instSet);

mr1.executeInst();

mr1.showCurrentLocation();

}

}

Plateau.java

import java.util.Scanner;

class Plateau {

private int size;

public Plateau() {

Scanner in = new Scanner(System.in);

System.out.println("Enter the Size of the plateau");

size=in.nextInt();

in.nextLine();

}

public Plateau(int sz){

size=sz;

}

public Cell getNeighbour(MarsRover.Direction dir,Cell c){

Cell neighbour = null;

switch (dir) {

case N:

neighbour=new Cell(c.x,c.y+1);

break;

case W:

neighbour=new Cell(c.x-1,c.y);

break;

case S:

neighbour=new Cell(c.x,c.y-1);

break;

case E:

neighbour=new Cell(c.x+1,c.y);

break;

}

if((neighbour.x>=0)&&(neighbour.y>=0)&&(neighbour.x

return neighbour;

return null;

}

}

Cell.java

class Cell{

int x;

int y;

public Cell(int PosX, int PosY) {

x=PosX;

y=PosY;

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!