Programming 3

University of Alicante, 2020–2021

First Programming Assignment

Deadline: Your assignment must be submitted before Sunday, September 27, 2020 at 23.59 (Alicante time). Late work will not be accepted. 
Relative weight of this assignment: 10%

Battleship

Introduction

In this first assignment, you will implement a new Java class from an already existing class implemented in C++. The objective of this assignment is to be aware of the main differences between Java and C++.

This class, which is a part of the model you will be working on during the semester, is called Coordinate. It represents a coordinate in the Battleship game board. Although in the game the coordinates are represented with a number and a letter, in our implementation we will represent them with two numbers (column and row).

The accompanying C++ code includes the destructor for the class. Since there is no exact translation of this to Java, we will omit it in the Java implementation. The operator == is equivalent to the ‘equals’ method of the Java implementation. The particularities of the Java implementation of the equals method will be discussed during the lab session. If you are using Eclipse you can use the option Source / Generate hashCode() and equals() from the menu. Make sure you properly understand the generated code. It is very important that you check that the implementation of equals() is conforming to the specifications. Read carefully the README.en.txt file accompanying the code for more information on the conversion of C++ code to Java.

Figure 1 provides the UML description of the Cordinate class.

Figure 1. UML class diagram.
Figure 1. UML class diagram.

Note that in C++ it is necessary to use a ‘dim’ attribute (which will be always set to 2, although it could change in forthcoming practical assignments), to store the size of the ‘components’ vector. In Java this attribute is not necessary because all vectors have a ‘length’ attribute: you must use ‘components.length’ instead of the ‘dim’ attribute of the C++ implementation.

In Java, the main function must be encapsulated within a class as a public and static method. This class is defined in file MainP1.java, which implements the same actions that the C++ code in file mainP1.cc. This will be the main program of this programming assignment. Yo do not have to implement it yourself. See below to know how to get it.

Unit tests (2nd lab session)

The file prog3-battleship-p1-pretest.tgz contains a folder named model containing unit tests. We will learn how to use this files to test our code during the second lab session.

Base Eclipse project (2nd lab session)

You will import it from here: Eclipse project template. It contains a pre-configured Eclipse project for the programming assignments. It contains the package mains under the src folder. Eclipse will generate the .classfiles under a bin folder which is not visible from Eclipse itself. This project already contains the file mains/MainP1.java. Follow your teacher’s instructions to import the project into Eclipse, and to add your own code to it.

Documentation

Source files must include all necessary comments in Javadoc format. These comments must be defined at least for:  

  • Files: annotation @author must include the name and ID number (DNI/NIE) of the authors.
  • Classes: 3 lines describing the main purpose of the class.
  • Operations: 1 line for trivial functions; 2 lines, input parameters, output parameters, and dependent functions for the rest.
  • Attributes: 1 line describing each attribute.  

Package structure and directories

Package structure is implemented in Java at the file-system level by conveniently using directories. This assignment has to be organised into two packages or directories:  

  • model : will contain the file Coordinate.java
  • mains : will contain the file MainP1.java

mains/MainP1.java can be used to check if your code at least compiles, as it calls every public method of class Coordinate. The result of its execution should be similar to the result of executing the C++ version.

Source files will contain the documentation in Javadoc format, but you do not need to include the HTML files generated by Javadoc in the compressed file.

Minimal requirements for grading your assignment

  • Your program must run with no errors. 
  • Unless otherwise stated, your program must not emit any kind of message or text through the standard output or standard error streams.  

  • The names of all properties (public, protected and private) of the classes, both in terms of scope of visibility and in terms of type and way of writing, must be rigorously respected, even if they are in Spanish. Make sure that you respect the distinction between class and instance attributes, as well as the uppercase and lowercase letters in the identifiers.
  • Your code must be conveniently documented and significant content has to be obtained after running the javadoc tool.  

Submission of the assignment

Upload your work to the DLSI submission server.

You must upload a compressed file with your source code (only .java files). In a terminal, go to the ‘src’ folder of your Eclipse project and type

tar czvf prog3-battleship-p1.tgz model

Upload the file prog3-battleship-p1.tgz to the server. Follow the instructions on the page to log in and upload your work.

Grading 

Testing of your assignment will be done automatically. This means that your program must strictly conform to the input and output formats given in this document, as well as to the public interfaces of all the classes: do not change the method signatures (name of the method, number, type and order of arguments, and data type returned) or their behaviour. For instance, method model.Coordinate(int,int) must accept two arguments of type int.

You can find more information about the grading of programming assignments in the subject description sheet.

In addition to the automatic grading, a plagiarism detection application will be used. The applicable regulations of the University of Alicante Polytechnic School in the event of plagiarism are indicated below:

“Theoretical/practical work must be original. The detection of copy or plagiarism will suppose the qualification of”0" in the corresponding assignment. The corresponding Department and the University of Alicante Polytechnic School will be informed about the incident.Repeated misconduct in this or any other subject will result in notification of the offences committed to the pertinent vice chancellor’s office so that they study the case and punish it in accordance with the legislation in force".

Clarifications

  • Although not recommended, you may add to your classes as many private attributes and methods as you wish. Notice, however, that you must implement all the methods indicated in this document and make sure that they work as expected, even if they are never called in your implementation. 
  • Any additional remark will be published in this page. It is recommended that you use this page as the primary source of the instructions.