Question: In this assignment, you will practice automated documentation generation using JavaDoc and Automated Unit Testing using Junit. In this assignment, you will reuse the code
In this assignment, you will practice automated documentation generation using JavaDoc and Automated Unit Testing using Junit.
In this assignment, you will reuse the code you submitted in Assignment 4 (the Moon Rover). You are free (but not required) to modify the code as you desire.
Part I: Automated documentation Generation (JavaDoc) (50%)
Use JavaDoc to automatically generate HTML pages. Your documentation should at minimum cover the following aspects:
a) Provide author and version information for each class.
b) Provide documentation for each method, clearly describing the purpose of the method and describe parameters it receives, and values it returns.
c) Describe attributes and provide rational of their use.
Part II: Unit Testing (JUnit) (50%)
Use Junit to create unit tests as follows. Each class should have a corresponding test class. Each method in your code should have a corresponding test method with multiple assertion statements (at least 3 assertion statements in each test case). Make sure to use diverse assertion statements to provide adequate testing of your code.
code from Assignment 4:
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
Get step-by-step solutions from verified subject matter experts
