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

CPSC 219: Mini-Assignment 2

Due Friday Feb 26 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 (in UNIX /home/219/assignments/mini_assignment2). 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 (null array element so a space is displayed) or the one element that refers to an Entity object (the 'appearance' attribute will determine what will be displayed under this case - 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 specified destination. 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]

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

Using pre-written Java code

You will need to use the built in code class Scanner for input. Beyond that (and common sense operators and functions such as those for output and mathematical operators), unless you told otherwise, you will need to write your own code and cannot use other pre-written Java classes or operators.

Points to keep in mind:

  1. Due time: All assignments are due at 4 PM on the due dates listed on the course web page.  Late assignments or components of assignments will not be accepted for marking without approval for an extension beforehand. What you have submitted in D2L as of the due date is what will be marked.
  2. Extensions may be granted for reasonable cases by the course instructor with the receipt of the appropriate documentation (e.g., a doctor's note). Typical examples of reasonable cases for an extension include: illness or a death in the family. Cases where extensions will not be granted include situations that are typical of student life: having multiple due dates, work commitments etc. Tutorial instructors (TA's) will not be able to provide extension on their own and must receive permission from the course instructor first. (Note: Forgetting to hand your assignment or a component of your assignment in does not constitute a sufficient reason for handing your assignment late).
  3. Method of submission: You are to submit your assignment using D2L [help link]. Make sure that you [check the contents of your submitted files] (e.g., is the file okay or was it corrupted, is it the correct version etc.). It's your responsibility to do this! (Make sure that your submit your assignment with enough time before it comes due for you to do a check).
  4. Identifying information: All assignments should include contact information (full name and student ID number) at the very top of your program in the class where the 'main()' function/method resides.
  5. Collaboration: Assignments must reflect individual work, group work is not allowed in this class nor can you copy the work of others.  For more detailed information as to what constitutes academic misconduct (i.e., cheating) for this course please read the following [link].
  6. Execution: programs must run on the computer science network.  If you write you code in the lab and work remotely using a remote login program such as Putty or SSH. If you choose to install Java on your own computer then it is your responsibility to ensure that your program will run properly here. It's not recommended that you use an IDE for writing your programs but if you use one then make sure that you submit your program in the form of individual text ".java" files (one for each class that you define).
  7. Source code: in order to get any credit for your work you must submit all relevant dot-java files for the assignment (e.g., Driver.java). If you only submit your byte code files (e.g. Driver.class) then you will not be awarded any credit.

D2L configuration for this course