Question
One java method test run I need help with... Java bug, would love some help... So basically the program is trying to create a 2d
One java method test run I need help with... Java bug, would love some help...
So basically the program is trying to create a 2d array that is filled with 4 randomly placed fish, which looks like: ><))">, 1 fish hook(J), and 6 fish food (*) and the rest of the characters are filled with ~ or water characters. And every time I run to test that the method placeObjectInTank() method correctly adds a fish at the specified position, I get the test feedback of "Failed to call method Main.placeObjectInTank(String, class [[C, Integer, Integer)." I would love to understand how I can fix this.
public class Main {
public static void main(String[] args)
{
char [][] tilde = new char [8][32];
fillTank(tilde, '~');
int fish [][] = generateRandomPositions(4, 8, 32);
for (int i = 0; i < fish.length; ++i)
placeObjectInTank("><))'>", tilde, fish[i][0], fish[i][1]);
moveAllObjects(fish, 1, 0, 8, 32);
int fishHook [][] = generateRandomPositions(1, 8, 32);
for (int i = 0; i < fishHook.length; ++i)
placeObjectInTank("J", tilde, fishHook[i][0], fishHook[i][1]);
moveAllObjects(fishHook, 0, 1, 8, 32);
int fishFood [][] = generateRandomPositions(6, 8, 32);
for (int i = 0; i < fishFood.length; ++i)
placeObjectInTank("*", tilde, fishFood[i][0], fishFood[i][1]);
moveAllObjects(fishFood, -1, -1, 8, 32);
renderTank(tilde);
}
public static void fillTank(char[][] tank, char water)
{
for (int row = 0; row < tank.length; ++row) {
for (int column = 0; column < tank[row].length; ++column) {
tank [row][column] = water;
}
System.out.println();
}
}
public static void placeObjectInTank(String object, char [][] positionInTank, int column, int row)
{
object.charAt(object.length() - 1);
int k = row;
for (int i = object.length() - 1; i >= 0; --i) {
positionInTank[column][k] = object.charAt(i);
k--;
if (k < 0) {
k = positionInTank[0].length-1; //looks at first row and finds first row
}
}
}
public static void renderTank(char[][] tank)
{
for (int row = 0; row < tank.length; ++row) {
for (int column = 0; column < tank[row].length; ++column) {
System.out.print(tank[row][column]);
}
System.out.println();
}
}
public static int[][] generateRandomPositions(int number, int width, int height)
{
int [][] randomPositions = new int [number][2]; //number of fish with coordinates
for (int i = 0; i < number; ++i) {
randomPositions [i][0] = Utility.randomInt(width);
randomPositions [i][1] = Utility.randomInt(height);
}
return randomPositions;
}
public static void moveAllObjects(int[][] positions, int dx, int dy, int width, int height)
{
for (int i = 0; i < positions.length; i++) {
positions[i][1] = (positions[i][1] + 1) % width;
}
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started