Description

You are to write part of a computer simulation. 'Entities' inhabit a 'World'. You are given the code for the 'Entity' class definition which can be found [here]. https://pages.cpsc.ucalgary.ca/~tamj/2021/233W/assignments/mini_assignment3/Entity.java Use this code when you implement class 'World' and the 'Driver' class. The latter will be starting execution point of the program containing the main method. You will receive credit for implementing the following capabilities in the World class. Although you aren't awarded direct credit for writing a proper Driver class it's obviously needed to run your program (but the Driver should be short - my solution was only two lines long).

Features of class World

  • Declares a 2D 5x5 "array of Entities". Each element refers to an Entity object.
  • Defines a constructor which initializes each array element to 'null'. The element at [1][1] will refer to an Entity object (the starting location of the one entity in the simulation).
  • Using nested loops the simulated world will be displayed. The appearance of an array element depends upon whether it is empty (space character) or the one element that refers to an Entity object (an X appears in the starting code for program but if the appearance is changed to another character (e.g. E then your program should display an 'E' and no an 'X' ). That is, the display of the Entity is based on the current value of the appearance attribute.
  • Each element is bound above, below, left and right by a line (see Figure 1).
    • Cases where every cell is bounded except for the following:
    • Misses one of the following: top row, bottom row, left row, right row.
    • Misses two of the following: top row, bottom row, left row, right row.
    • Misses three of the following: top row, bottom row, left row, right row.
    • Misses all of the following: top row, bottom row, left row, right row.
    • Cases where only the outer boundary is bounded:
    • Only the very top AND the bottom is bounded.
    • Only the very top OR the bottom is bounded.
  • Loop the display of the world until the user enters a negative location for the row or column (next feature).
  • (1) Prompts the user for the destination (row/column) to move the entity. (2) A negative value for either coordinate will end the program (regardless of what value was entered for the other coordinate e.g., (-1/-1), (-1,0), (20,-22) will all end the program). (3) A value outside the bounds of the array will result in an appropriate error message, non-negative out-of-bound values will still allow the program to prompt again as long as the other coordinate is not negative.
  • (The previous feature must be implemented first). Assuming that no out-of-bound coordinates have been entered, the program "moves" the entity to the specified destination. The previous cell will appear 'empty' (space) whereas the destination will take on the appearance of the entity ('X' in the starting code). Movement must work for multiple turns in order to get credit (and not just 'apparently' work for one turn and thereafter producing an incorrect result).

Figure 1: The display of array elements bounded in the four directions (starting location of object at [1][1]): see image.

Figure 2: Any out-of-bound destinations will result in an error message. Any negative coordinates will end the simulation program: see image.

To help you see the operation of the various features there is a sample output file in the assignment directory: [output.txt] https://pages.cpsc.ucalgary.ca/~tamj/2021/233W/assignments/mini_assignment3/output.txt

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.