1.11M Members

Hey, I'm new to this site and asking for help in general, but this prompt my teacher gave us to do makes no sense to me at all. I dont know if he is asking us to input values manually from the keyboard into the 2 dimensional array or if we are supposed to use random numbers. I don't even know if I am going about this the correct way, I have a hard time translating the prompts into code, so if someone could help me out that would be great. This is what I have so far :

import java.util.*;
public class Food
{
public static void main(String[]args)
{
System.out.println("Enter values");
Scanner input = new Scanner(System.in);
int num1 = input.nextInt();
int num2= input.nextInt();
int [][]amount = new int [num1][num2];
// print array in rectangular form
for (int r=0; r<amount.length; r++) {
for (int c=0; c<amount[r].length; c++) {
System.out.print(" " + amount[r][c]);

}
System.out.println("");
}
}
}

Write a program in which a cat finds the best path from the upper left corner, (0,0), to the lower right corner, (SIZE-1, SIZE-1), in a food grid, which is a two-dimensional array. Each array location contains either a quantity of food, represented by a non-negative integer, or a barrier, represented by the value -1.

For each step the cat can move only down or to the right. The cat is not allowed to step into a barrier element. The optimal path contains the largest amount of food.

The program reads the food grid from the keyboard and reports the optimal path and the amount of food it contains. The input should consist of rows of integers, each integer representing a grid value.

If there is only one way to move, then move there and update the total accumulated amount of food. If there are two ways to move, save one of the possible moves and its total on a stack, and make the other move. If you have reached the lower right corner, update the maximum. If there is nowhere to go, examine the stack, pop a saved move, if any, and resume from there.

looks to me like you have to input the values for the elements manually, that is, going on this:

The program reads the food grid from the keyboard

You