Java - error: the constructor "constructor name" in the class "class name" cannot be applied to the specified types;

Before I ask my question, I want to make some things clear. Firstly, I am new to Java and programming in general. Secondly, this is my first post, so please calm down if I did something wrong. Finally, I DO NOT NOT wish for any specific solutions for my assignment in any responses to this post. I have to find out these questions. What I want is an explanation of why my test code will not compile / execute. To better understand the problem, I will insert the destination information, and then the provided driver class, and then the class code that the driver class accesses. The compiler error indicated in the header, but since it is rather vague, here is a screenshot of the exact errors I get.

The following is the purpose:

You must create the class "LostPuppy.java", which represents a puppy lost in a multi-story building that contains the same number of rooms on each floor. During the creation (or creation) of an object of this class, each room on each floor will be initialized as empty (in fact, you will use a space character for this), and a random room will be selected where the puppy is lost. For this purpose, the character ā€œPā€ will be placed at this random location. More detailed information about the constructor is given below.

An object of this class is used as a game for two players to alternately look for a puppy, one room in, until an unfortunate little fang is found. This object will be instantiated and searched by the "program" that was provided to you, allowing you to focus only on the development of the class (the driver program is in the file "PuppyPlay.java")

Fields (of course, all fields are private):

  • An array (char) named myHidingPlaces. This is a building where rows of floors and columns are rooms on each floor (this building has an unusual numbering system, floors and rooms start from scratch).

  • The two integers that will hold the floor and the room where the puppy is lost are called myFloorLocation and myRoomLocation.

  • A char myWinner, , ( "1" "2", ).

  • myFound, true, .

:

  • , .

  • 2D- "myHidingPlaces" (theFloors) (theRooms).

  • myHidingPlaces, '' ( )

  • myFloorLocation ( ), ,
  • myRoomLocation ( ) ,
  • myHidingPlaces [myFloorLocation] [myRoomLocation] char 'P
  • myWinner
  • myFound false

:

  • roomSearchedAlready true, , false .

  • puppyLocation true, , - . .

  • indexOK true, , false ( , ).

  • numberOfFloors ( ).

  • numberOfRooms ( ).

  • searchRoom , ( char), true, , false. , searchRoom myHidingPlaces (a '1 '2) , , myWinner myFound true.

  • toString hidingPlaces , , toString (), , , "P" ....

  • , , toString. , 2D-, [0] [0] , . , , , ( 0) , ... , , , ... ! , , . , .

:

import java.util.Random;
import java.util.Scanner;

/**
 * This program is used as a driver program to play the game from the
 * class LostPuppy.  Not to be used for grading!
 *
 * A puppy is lost in a multi-floor building represented in the class 
 * LostPuppy.class.  Two players will take turns searching the building
 * by selecting a floor and a room where the puppy might be.
 *
 * @author David Schuessler
 * @version Spring 2015
 */

public class PuppyPlay
{
  /**
   * Driver program to play LostPuppy.
   *
   * @param theArgs may contain file names in an array of type String
   */
  public static void main(String[] theArgs)
  {
    Scanner s = new Scanner(System.in);
    LostPuppy game; 
    int totalFloors;
    int totalRooms;
    int floor;
    int room;
    char[] players = {'1', '2'};
    int playerIndex;
    boolean found = false;
    Random rand = new Random();

    do 
    {
      System.out.print("To find the puppy, we need to know:\n"
                       + "\tHow many floors are in the building\n"
                       + "\tHow many rooms are on the floors\n\n"
                       + "             Please enter the number of floors: ");
      totalFloors = s.nextInt();
      System.out.print("Please enter the number of rooms on the floors: ");
      totalRooms = s.nextInt();
      s.nextLine();    // Consume previous newline character    

      // Start the game: Create a LostPuppy object:
      game = new LostPuppy(totalFloors, totalRooms);

      // Pick starting player
      playerIndex = rand.nextInt(2);

      System.out.println("\nFloor and room numbers start at zero '0'");

      do 
      {

        do 
        {
          System.out.println("\nPlayer " + players[playerIndex]
                             + ", enter floor and room to search separated by a space: ");
          floor = s.nextInt();
          room = s.nextInt();

          //for testing, use random generation of floor and room
          //floor = rand.nextInt(totalFloors);
          //room = rand.nextInt(totalRooms);
        } while (!game.indicesOK(floor, room) 
                 || game.roomSearchedAlready(floor, room));


        found = game.searchRoom(floor, room, players[playerIndex]);
        playerIndex = (playerIndex + 1) % 2;
        System.out.println("\n[" + floor + "], [" + room + "]");
        System.out.println(game.toString());
        s.nextLine();
      } while (!found);

      playerIndex = (playerIndex + 1) % 2;
      System.out.println("Great job player " + players[playerIndex] +"!");
      System.out.println("Would you like to find another puppy [Y/N]? ");
    } 
    while (s.nextLine().equalsIgnoreCase("Y"));
  }
}

, :

import java.util.Random;
import java.util.Scanner;

public class LostPuppy
{

   char[][] myHidingPlaces;
   int myFloorLocation;
   int myRoomLocation;
   char myWinner;
   boolean myFound;
   Random random = new Random();

   public void LostPuppy(int theFloors, int theRooms)
   {// this ^ void is the issue and is now removed from my code(answered 7/14/2015 on stack overflow)
      char[][] myHidingPlaces = new char[theFloors][theRooms];

      for (int i = 0; i < theFloors; i++)
      {
         for (int j = 0; j < theRooms; j++)
         {
            myHidingPlaces[i][j] = ' ';
         }
      }

      myFloorLocation = random.nextInt(theFloors);
      myRoomLocation = random.nextInt(theRooms);
      myHidingPlaces[myFloorLocation][myRoomLocation] = 'P';
      myWinner = ' ';
      myFound = false;  
   }
   public boolean roomSearchedAlready(int floor, int room)
   {
      if (myHidingPlaces[floor][room] == '1' || 
          myHidingPlaces[floor][room] == '2')
          {
            return true;
          }
      else
      {
         return false;
      }
   }

   public boolean puppyLocation(int floor, int room)
   {
      if (myHidingPlaces[floor][room] == 'P')
      {
         return true;
      }
      else
      {
         return false;
      }
   }

   public boolean indicesOK(int floor, int room)
   {
      if (floor <= myHidingPlaces.length || room <= myHidingPlaces[0].length)
      {
         return true;
      }
      else
      {
         return false;
      }
   }

   public int numberOfFloors()
   {
      return myHidingPlaces.length - 1;
   }
   public int numberOfRooms()
   {
      return myHidingPlaces[0].length - 1;
   }

   public boolean searchRoom(int floor, int room, char player)
   {
      if (myFound = true)
      {
         myWinner = player;
         myFound = true;
         return true;
      }
      else
      {
         myHidingPlaces[floor][room] = player;
         return false;
      }
   }

   public String toString()
   {
      return "this is a test";

   }

}
+4
2

. . , , /.

game = new LostPuppy(totalFloors, totalRooms);

, - , int (totalFloors totalRooms).

, LostPuppy ,

public LostPuppy(int totalFloors, int totalRooms)
{
    //Do something here with paremeters..
}

while (!game.indicesOK(floor, room) 

, - indicesOk LostPuppy.

,

public boolean indicesOK(int floot, int room)
{
    //return some conditions
}
+5

, building :

public LostPuppy(int theFloors, int theRooms)
{
  myHidingPlaces = new char[theFloors][theRooms]; //this line

  for (int i = 0; i < theFloors; i++)
  {
     for (int j = 0; j < theRooms; j++)
     {
        myHidingPlaces[i][j] = ' ';
     }
  }

  myFloorLocation = random.nextInt(theFloors);
  myRoomLocation = random.nextInt(theRooms);
  myHidingPlaces[myFloorLocation][myRoomLocation] = 'P';
  myWinner = ' ';
  myFound = false;  
}

: , , , .

+2

All Articles