Question: I NEED JUNIT5 TESTING FOR THESE THREE CLASSES. tHE FORMAT FOR THE CODE HAS TO STAY THE SAME BUT IF SOMETHING IN IT IS WRONG

I NEED JUNIT5 TESTING FOR THESE THREE CLASSES. tHE FORMAT FOR THE CODE HAS TO STAY THE SAME BUT IF SOMETHING IN IT IS WRONG PLEASE FEEL FREE TO CHANGE IT. One or two tests per thing is fine

public class Fleet implements FleetAPI {

private static final int fleetSize = 7; private Ship[] ships; private Location location;

= public Fleet() { ships = new Ship[fleetSize]; }

public void deployFleet() { for (int i = 0; i < fleetSize; i++) { ships[i] = new Ship(); location.pick(); while (check(location) >= 0) { location.pick(); } ships[i].setLocation(location); } }

public boolean operational() { for (int i = 0; i < fleetSize; i++) { if (!ships[i].isSunk()) { return true; } } return false; }

public boolean isHitNSink(Location loc) { int index = check(loc); if (index >= 0) { ships[index].sink(); return true; } return false; }

public void printFleet() { for (int i = 0; i < fleetSize; i++) { ships[i].printShip(); } }

public int check(Location loc) { for (int i = 0; i < fleetSize; i++) { if (ships[i].match(loc)) { return i; } } return -1; } }

----------------------------------------------------------------------------------------

public class Location implements LocationAPI {

private final static int feildSIze= 7; int x = -1; char y = '*';

public Location() { }

@Override public void pick() { Random rand = new Random(); x = rand.nextInt(feildSIze) + 1; y = (char) ('a' + rand.nextInt(feildSIze));

switch (x) { case 1: y = 'a'; break; case 2: y = 'b'; break; case 3: y = 'c'; break; case 4: y = 'd'; break; case 5: y = 'e'; break; case 6: y = 'f'; break; case 7: y = 'g'; break;

} }

@Override public void fire() { Scanner sc = new Scanner(System.in); System.out.println("Enter the coordinate to fire (e.g. a1): "); String input = sc.nextLine(); y = input.charAt(0); x = Integer.parseInt(input.substring(1)); }

@Override public void print() { System.out.println(y + "" + x); } } -------------------------------------------------------------------------------

public class Ship implements ShipAPI { private Location loc; private boolean sunk;

public Ship() { sunk = false; loc = new Location(); }

@Override public boolean match(Location location) { return loc.x == location.x && loc.y == location.y; }

@Override public boolean isSunk() { return sunk; }

@Override public void sink() { sunk = true; }

@Override public void setLocation(Location location) { loc = location; }

@Override public void printShip() { System.out.print(loc.y + "" + loc.x + " "); if (sunk) { System.out.println("sunk"); } else { System.out.println("up"); } } }

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!