CS1331 Homework 5 - Collections

HW5 Files

Introduction

This assignment will involve Collections, generics, iterators, and the Comparable interface.

Description

Winter is here. The Long Night has arrived. The cold winds blow from the north. Westeros is faced with the impending invasion of the sinister White Walkers. You are trying to build a team to take north of the Wall in order to fight them. However, in order to save Westeros, you have to know about Collections. After all, how can you keep track of your team without Collections?

This assignment will have you implement a generic ComparableCollection that can only take in Comparable objects. We have provided a generic interface CollectionInterface that contains the methods you must implement in your ComparableCollection. It is your job to build a concrete implementation that allows for your ComparableCollection to only handle objects that are Comparable. Additionally, your ComparableCollection must be Iterable. You will then have to implement a TeamWrapper class. This will use your ComparableCollection to allow you to build your team and manipulate it. You will also have to implement a Character class that represents the people you might add to your team. Character must be Comparable.

Provided Files and Solution Description

You will have to modify the files Character.java, ComparableCollection.java, and TeamWrapper.java.

CollectionInterface.java

DO NOT MODIFY THIS FILE. This interface contains the following methods. Refer to the javadocs for a more detailed description of each method.

ComparableCollection.java

Character.java

A class representing the people you will attempt to recruit. This class MUST BE COMPARABLE. Characters can only be compared to other Characters. Characters should be compared by the sum of combatSkill and intelligenceLevel. Character has the following instance fields:

You only need to implement one constructor that takes in and sets all the instance fields. You will need to implement getters and setters for all of the instance fields. In addition to getters and setters, you must implement the following:

TeamWrapper.java

This is a Wrapper that will be used to build your team. You will have a main team and a reserve team. This class has two private instance fields that have been provided. They have been instantiated for you in a constructor. One is a ComparableCollection that represents your main team. You will also have a reserve team represented by another ComparableCollection. Your main team is what you will bring to the fight, and your reserve team has your backup fighters if any of your main team die prematurely, which knowing George R.R. Martin is a real possibility. Your main team can have no more than 10 fighters, and your reserve can have no more than 5. You should be able to move fighters from your reserve to your main team and vice versa. You will have to implement the following methods.

See the provided javadocs for more details on these methods.

Note: You should not be able to add the same Character to both your team and reserve team.

The following methods are provided, DO NOT MODIFY THEM.

BuildTeam.java

DO NOT MODIFY THIS. This will take you through a simulation of traveling Westeros looking for Characters to add to your team. Simply follow the on screen instructions. If your TestWrapper.java is working as it should, BuildTeam.java should run smoothly.

Tips

Compiling and Testing Your Code

You should not use any methods, libraries or packages that trivialize the assignment. If you are unsure of whether something is allowed, ask on Piazza. In general, if something does a large part of the assignment for you, it is probably not allowed. Important: java.util.Arrays is not allowed. However, that is different from a Java array (e.g int[] nums = new int[10]), which is necessary for this assignment.

To compile your code simply run javac *.java from the directory in which your files are located. We have provided a file called BuildTeam.java. DO NOT MODIFY THIS. If your TestWrapper class functions as it should, running java BuildTeam will take you through a simulation of Westeros where you travel and attempt to build your team. Follow the on screen instructions when you run it. Keep in mind that even it runs properly, this DOES NOT GUARANTEE that your code is 100% correct. The following is a list, not exhaustive, of things you need to make sure you’ve done.

Refer to the method descriptions to make sure that you have implemented all then necessary functionality.

Javadocs

Checkstyle

You must run checkstyle on your submission. The checkstyle cap for this submission is 70 points. YOU DO NOT NEED TO RUN CHECKSTYLE ON BuildTeam.java. Simply move the file to another directory and run checkstyle on the files that you had to modify.

A guide for setting up and running checkstyle can be found on this page on the course website. Make sure you click “Save” when downloading the jar file, and not “Run”. It is useful to copy the jar file to your homework directory or set up an alias for it. Run checkstyle for this assignment with java -jar checkstyle-6.2.2.jar -a *.java. This will check for both checkstyle errors and javadoc errors.

Collaboration with other students When completing homeworks for CS1331 you may talk with other students about:

You may not discuss, show, or share by other means the specifics of your code, including screenshots, file sharing, or showing someone else the code on your computer, or use code shared by others.

Examples of approved/disapproved collaboration:

Collaborating with others in a way that violates the approved means is a Georgia Tech Honor Code violation.

Turn-in Procedure

YOUR SUBMISSION SHOULD ONLY CONTAIN .JAVA FILES!

Compress the Hw5 files into a .zip file and submit that on T-square. Make sure the zip file contains CollectionInterface.java, ComparableCollection.java, Character.java, TeamWrapper.java, and BuildTeam.java. Do NOT submit your .class files.

Verify the Success of Your Submission to T-Square

Practice safe submission! Verify that your HW files were truly submitted correctly, the upload was successful, and that your program runs with no syntax or runtime errors. It is solely your responsibility to turn in your homework and practice this safe submission safeguard.