Course web page: Introduction to Computer Science for majors II James Tam Return to the course web page

CPSC 233: Mini-Assignment #3

Due October 16 at 4 PM

New Concepts to be applied for the assignment

Description

You are to write part of a computer simulation. 'Entities' inhabit a 'World'. You are given the code for the 'Entity.java' class definition which can be found in the assignment directory. Use this code to 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:

 Features of class World

  • Declares a 2D 5x5 array as an attribute. Each element refers to an Entity object (1 mark)
  • 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). (2 marks: 1 for initializing whole array to null and 1 for setting the starting location of the entity object)
  • 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 (the 'appearance' attribute will be used - don't just hard code your output to the 'X' or you won't get credit. Your program MUST be able to tell the difference between a null element and a reference to an entity) (2 marks: 1 for each case)
  • Each element is bound above, below, left and right by a line (see Figure 1). (4 marks for every element properly bounded: 2 marks if bounded lines appear but (misses the top or bottom row) AS WELL AS (missing the first or last column), 3 marks if bounded lines appear but EITHER the top/bottom or far left/right is missed)
 
Figure 1: The display of array elements bounded in the four directions (starting location of object at [1][1])
  • Loop the display of the world until the user enters a negative location for the row or column (next feature). (1 mark)
  • (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 loop again as long as the other coordinate is not negative. (3 marks: 1 for each feature)
 
Figure 2: Any out-of-bound destinations will result in an error message. Any negative coordinates will end the simulation program.
  • (The previous feature must be implemented first). Assuming that no out-of-bound coordinates have been entered, the program "moves" the entity to the specifieddestination. The previous cell will appear 'empty' whereas the destination will take on the appearance of the entity. (7 marks: 4 marks for destination cell, 3 marks for the source cell). Movement must work for multiple turns in order to get credit (and not just 'apparently' work for one turn)

To help you see the operation of the various features there is a sample output file in the assignment directory: [output.txt]

Submitting your work:

  1. Assignments (source code/'dot-java' file) must be electronically submitted according to [the assignment submission requirements] using [D2L].
  2. As a reminder, you are not allowed to work in groups for this class. Copying the work of another student will be regarded as academic misconduct (cheating).  For additional details about what is and is not okay for this class please refer to the following [link].

Marking key

Marks earned 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Grade point 4.0 3.8 3.6 3.4 3.2 3 2.8 2.6 2.4 2.2 2 1.8 1.6 1.4 1.2 1.0 0.8 0.6 0.4 0.2 0

External libraries that can be used (unless otherwise you can not assume that you can use the library).

  1. You cannot use methods other than the ones for output: printf(), print(), println().