Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: School project help

  1. #1
    Junior Member
    Join Date
    Feb 2022
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default School project help

    Hello. I am in desperate need of help for a school project. It is due today at 11:59pm CDT. I genuinely do not even know where to begin.

    Lab Description : Ben loves Kitties and his kitties are running free. You need to help Ben identify where his kitties are so he can get them all rounded up.
    Each cell in the boolean matrix that contains a kitty will be set to true. Each cell that contains no kitty will be set to false. Use Math.random() to randomly place the 0s and 1s in the grid – try multiplying by numbers larger than 2 if you want fewer kitties in the grid.
    As you work to help Ben recover his lost kitties, you will create an integer matrix that stores the number of kitties near each cell. Each cell that contains a kitty is set to 9. All other cells are set to the value of how many kitties are around them. This integer grid will be used to determine the best location from which to start collecting Ben’s kitties.
    Bonus Challange: Write a method to find the best place to drop a kitty collecting robot. The robot will fan out in all directions and collect all kitties within a 3 cell radius. Your method should return the location of the best place to drop the robot.
    Boolean matrix(all random)

    0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0
    0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 1
    0 0 0 0 1 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 1 1 0 1 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0
    0 0 1 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 0
    0 1 0 0 0 0 0 0 0 0 0 0 0 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 1 0 0 0 0 0 0
    0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0
    0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
    0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0
    1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 1 0 0
    0 0 0 0 0 0 0 1 0 0 1 0 0 1 1 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0

    Cat Location Matrix(you must calculate from your boolean matrix)

    0 0 0 0 0 0 1 9 1 0 0 0 2 9 2 0 0 1 1 1
    0 0 0 0 0 0 1 1 1 0 0 0 3 9 4 1 1 1 9 2
    0 0 0 1 1 1 1 1 2 1 1 0 2 9 3 9 1 1 2 9
    0 0 0 1 9 1 1 9 3 9 3 2 2 2 2 1 1 0 1 1
    0 0 0 1 1 1 2 2 4 9 9 3 9 1 0 0 0 0 0 0
    0 1 1 1 0 0 2 9 3 3 9 5 3 2 0 0 0 0 0 0
    1 2 9 1 0 0 2 9 2 1 2 9 9 1 0 0 0 0 1 1
    1 9 2 1 0 0 1 1 1 0 1 2 3 2 1 0 0 0 1 9
    1 1 1 0 0 0 0 0 0 0 1 1 2 9 1 1 1 1 1 1
    0 0 0 0 0 0 0 0 0 0 1 9 2 1 1 1 9 1 1 1
    0 0 0 0 0 0 1 1 1 0 1 1 1 0 0 1 1 1 1 9
    0 0 0 0 1 1 2 9 1 0 1 1 2 1 1 0 0 0 1 1
    0 0 0 0 2 9 3 1 2 1 2 9 2 9 1 0 0 0 0 0
    0 0 1 1 3 9 2 1 2 9 2 1 2 1 1 0 0 0 0 0
    0 0 2 9 3 1 2 2 9 2 1 0 0 0 0 0 0 0 0 0
    1 1 2 9 2 0 1 9 2 1 0 0 0 0 0 0 0 0 0 0
    9 1 1 1 1 0 1 1 1 0 0 1 1 2 1 1 1 1 1 0
    1 1 0 0 0 0 1 1 1 1 1 2 9 4 9 2 1 9 1 0

    Here is what is in Main.java:
    import java.io.File;
    import java.io.IOException;
    import java.util.Scanner;
    import static java.lang.System.*;
     
    class Main {
    public static void main(String[] args) {
    KittyMap km = new KittyMap(10, 10);
    System.out.println( km + "\n\n");
    km.printKittyCount();
    }
    }
    Here is what is in KittyMap.java:
    import java.util.Scanner;
    import static java.lang.System.*;
     
    public class KittyMap
    {
    private boolean[][] kittyGrid;
     
    /*
    *this constructor loads in random true and false values
    */
    public KittyMap(int rows, int cols)
    {
    }
     
    /*
    *this method will call getKittyCountsGrid
    *to retrieve the kitty counts for the kittyGrid
    */
    public void printKittyCount()
    {
    }
     
    /*
    *this method will calculate the kitty counts for each cell
    *if cell is true set int value to 9
    *if cell is not true set int value to cnt of kitties in adjacent cells
    */
    private int[][] getKittyCountsGrid()
    {
    return null;
    }
     
    /*
    *this method will return the value of the current cell
    *if this cell contains a kitty - return 9
    *otherwise - return the cnt of all kitties in adjacent cells
    */
    public int getKittyCount( int r, int c)
    {
    return 0;
    }
     
    /*
    *check r and c to ensure they are inside the grid
    */
    private boolean inBounds( int r, int c)
    {
    return false;
    }
     
    /*
    *return the kitty grid as a string
    */
    public String toString()
    {
    String output="";
    return output.trim();
    }
    }
    Last edited by starcoveredhoney; February 28th, 2022 at 07:02 PM. Reason: formatting problems

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,166
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: School project help

    What is the logic have you worked on to solve the problem?


    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Feb 2022
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: School project help

    My dad and I just sat down and worked on it together for a bit and this is what he gave me to work on. I'm still really confused.
    import java.util.Scanner;
    import static java.lang.System.*;
     
    public class KittyMap
    {
    	private boolean[][] kittyGrid;
      private int[][] kittyCountGrid;
      private int rowCount;
      private int colCount;
     
    	/*
    	 *this constructor loads in random true and false values
    	 */
    	public KittyMap(int rows, int cols)
    	{
        kittyGrid = new boolean[rows][cols];
        kittyCountGrid = new int[rows][cols];
     
          rowCount = rows;
          colCount = cols;
     
          initKittyCountGrid();
    	}
     
      private void initKittyCountGrid()
      {
        for (int row = 0; row < rowCount; row++)
          {
            for (int col = 0; col < rowCount; col++)
              {
                kittyCountGrid[row][col] = 0;
              }
          }
      }
    	/*
    	 *this method will call getKittyCountsGrid
    	 *to retrieve the kitty counts for the kittyGrid
    	 */
    	public void printKittyCount()
    	{
        for (int row = 0; row < rowCount; row++)
          {
            for (int col = 0; col < rowCount; col++)
              {
                //more here
                 System.out.print(kittyCountGrid[row][col]);          }
          }
    	}
     
    	/*
    	 *this method will calculate the kitty counts for each cell
    	 *if cell is true set int value to 9
    	 *if cell is not true set int value to cnt of kitties in adjacent cells
    	 */
    	private int[][] getKittyCountsGrid()
    	{
        for (int row = 0; row < rowCount; row++)
          {
            for (int col = 0; col < rowCount; col++)
              {
                // 
                // hardwork in here, yada yada yada
              }
            }
     
     
     
                return kittyCountGrid;
    	}
     
    	/*
    	 *this method will return the value of the current cell
    	 *if this cell contains a kitty - return 9
    	 *otherwise - return the cnt of all kitties in adjacent cells
    	 */
    	public int getKittyCount( int r, int c)
    	{
    		return 0;
    	}
     
    	/*
    	 *check r and c to ensure they are inside the grid
    	 */
    	private boolean inBounds( int r, int c)
    	{
    		return false;
    	}
     
    	/*
    	 *return the kitty grid as a string
    	 */
    	public String toString()
    	{
    		String output="";
    		return output.trim();
    	}
    }

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,166
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: School project help

    I'm still really confused.
    What part are you confused about? Please explain.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Need help with A school project!
    By D4TH in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 2nd, 2017, 10:07 AM
  2. Java School Project Help; Project #2, In Danger of Failing.....
    By john++ in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 2nd, 2014, 02:35 AM
  3. School project
    By midnight21 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: September 21st, 2013, 03:48 PM
  4. [SOLVED] Help with school project
    By mattisvan in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 15th, 2013, 07:22 AM
  5. school project
    By robin28 in forum Java Theory & Questions
    Replies: 13
    Last Post: November 12th, 2010, 09:11 AM