Problem Description
Having now solved the Pokemon health crisis, word of your programming ability quickly spreads throughout the land like a cool seed in The Game of Life. One day, you receive an email:
Hello there! Welcome to the world of POKEMON! My name is OAK! People call me the POKEMON PROF!
This world is inhabited by creatures called POKEMON! For some people, POKEMON are pets. Others use them for fights. MyselfI study POKEMON as a profession.
You soon learn that Oak is a professor at Georgia Tech University, which, he assures you, is a well known school. He wants you to help him write software to catalog and organize Pokemon so he can better research them. At first youre skeptical, but once he promises you meal swipes, you promptly get to programming.
Solution Description
For this assignment, create the following files:
- java
- java
- java
PokemonSpecies Class:
In the world of Pokemon all species of Pokemon (the equivalent of animals in this world) have been assigned a number for ease of reference and sorting. This representation of a PokemonSpecies, therefore, should implement the Comparable interface. A PokemonSpecies is greater when it has a higher speciesNumber; a PokemonSpecies is lesser when it has a lower speciesNumber.
Variables:
- speciesNumber, an int that represents the specific species of a given PokemonSpecies. Once set, this should not be changeable outside this class.
- speciesName, a String holding the name of the species. Once set, this should not be changeable outside this class.
- speciesNickname a String holding the nickname of the PokemonSpecies
- description a String holding a description of the PokemonSpecies.
Constructors:
- PokemonSpecies(String speciesName, int speciesNumber, String speciesNickname, String description)
- Sets speciesName, speciesNumber, speciesNickname, and description
- PokemonSpecies(String speciesName, int speciesNumber)
- Sets speciesName and speciesNumber. speciesNickname and description should be set to null.
Methods:
- int compareTo(PokemonSpecies other)
- boolean equals(Object other) PokemonSpecies are considered equal if they have the same speciesName and speciesNumber.
- int hashCode() Write a proper hashCode for PokemonSpecies that considers the proper fields (Hint: Look at equals)
- String toString() Should return [speciesNumber]: [speciesName], the [speciesNickname] Pokemon.
[speciesDescription].
- Getters for all fields.
- Setters for speciesNickname, description.
AbstractDex Class:
This class should be generic. The generic type should be bounded such that you can perform searching and sorting operations on a List of any generic type that can be sorted. We will refer to the generic as T but you can name it what you want as long as you follow the proper conventions. Because this simply serves as a base of reusable code for any type of dex, it should be abstract.
Instance Variables:
- ArrayList<T> entries An ArrayList of objects that are comparable to each other.
- boolean sorted A boolean value storing whether or not entries have already been sorted by the dex.
Constructors:
- AbstractDex() Initializes entries to an empty ArrayList Methods:
- void insertionSort() sorts entries using the insertionSort() algorithm taught in class. Sets sorted to true
- void selectionSort() sorts entries using the selectionSort() algorithm taught in class. Sets sorted to true.
- int binarySearch(T element) searches entries for the passed in element using the binary search algorithm taught in class, returning its index if found or -1 if not found or sorted is false. DO NOT USE JAVAS BUILT IN indexOf() METHOD.
- void addToDex(T newElement) If there is not already an equivalent element in entries, as determined by compareTo(), add newElement to the end of entries and set sorted to false.
- boolean equals(Object other) Write a proper equals method for AbstractDex. Two AbstractDex objects are considered equal if they have the same entries. For comparison, you can use ArrayLists equals() method.
- int hashCode() Write a proper hashCode for a AbstractDex, using only the proper fields. (Hint: look at equals). You can use ArrayLists hashCode() method.
- String toString() Should loop through each entry and call its toString(). Separate the outputs with newline characters. An example of what this should look like can be found in the sample tests.
- Getters for entries and sorted.
- Setter for entries.
Pokedex Class:
Is a concrete subclass of AbstractDex which holds PokemonSpecies only (Hint: how can we extend AbstractDex to only allow PokemonSpecies) Constructors:
- Pokedex() initializes entries to an empty ArrayList
- Pokedex(ArrayList<PokemonSpecies> initialEntries) initializes entries with the elements in the passed in List.
Testing your code:
If you want to test out your own code before submitting we recommend creating a separate java file and implementing a main method there. You can then create new animals and test your methods. Below is some sample testing code. These tests are not comprehensive!
Pokedex myPokedex = new Pokedex();PokemonSpecies carl = new PokemonSpecies(Carl, 1, Head TA,Its Mixtapes are said to be too hot for the average listener); System.out.println(carl);// 1: Carl, the Head TA Pokemon. Its Mixtapes are said to be too hot for the average listener.PokemonSpecies karl = new PokemonSpecies(Karl, 2, Spooky TA,It is said Karl can be found lurking in Klaus during spooktober);PokemonSpecies qarl = new PokemonSpecies(Qarl, 3, Checkstyle TA,Qarl likes to remind students to checkstyle their work);System.out.println(qarl.compareTo(karl));// positive number myPokedex.addToDex(karl); myPokedex.addToDex(qarl); myPokedex.addToDex(carl); myPokedex.insertionSort();System.out.println(myPokedex.binarySearch(carl));// 0System.out.println(myPokedex.binarySearch(karl));// 1System.out.println(myPokedex.binarySearch(qarl));// 2Pokedex secondPokedex = new Pokedex();secondPokedex.addToDex(qarl); secondPokedex.addToDex(carl); secondPokedex.addToDex(karl); secondPokedex.selectionSort();System.out.println(myPokedex.binarySearch(carl));// 0System.out.println(myPokedex.binarySearch(karl));// 1System.out.println(myPokedex.binarySearch(qarl));// 2System.out.println(myPokedex.equals(secondPokedex));// trueSystem.out.println(myPokedex);/*1: Carl, the Head TA Pokemon. Its Mixtapes are said to be too hot for the average listener.2: Karl, the Spooky TA Pokemon. It is said Karl can be found lurking in Klaus during spooktober.3: Qarl, the Checkstyle TA Pokemon. Qarl likes to remind students to checkstyle their work. */ |
Feel free to create your own tests in the main method! Try to write tests for the remaining methods in the file!
Rubric
- [35] PokemonSpecies
- [5] Correct Fields
- [5] Correct Constructors
- [5] equals(Object)
- [5] compareTo(PokemonSpecies)
- [5] hashCode()
- [5] toString()
- [5] Getters and Setters
- [60] AbstractDex
- [5] Generic with correct type bounds
- [4] Correct Constructor
- [1] Correct Field
- [10] insertionSort()
- [10] selectionSort()
- [10] binarySearch(T element)
- [5] addToDex(T element)
- [5] equals(Object)
- [5] hashCode()
- [5] toString()
- [5] Pokedex
- [5] Correct Constructors
Allowed Imports
- To prevent trivialization of the assignment, you are only allowed to import the following class:
java.util.ArrayList
Javadocs
For this assignment, you will be commenting your code with Javadocs. Javadocs are a clean and useful way to document your codes functionality. For more information on what Javadocs are and why they are awesome, the online overview for them is extremely detailed and helpful.
You can generate the javadocs for your code using the command below, which will put all the files into a folder called javadoc:
$ javadoc *.java -d javadoc
The relevant tags that you need to include are @author, @version, @param, and @return. Here is an example of a properly Javadocd class:
import java.util.Scanner;/*** This class represents a Dog object.* @author George P. Burdell* @version 1.0*/ public class Dog {/*** Creates an awesome dog (NOT a dawg!) */ |
public Dog() { }/*** This method takes in two ints and returns their sum* @param a first number* @param b second number * @return sum of a and b*/public int add(int a, int b) {}} |
A more thorough tutorial for Javadocs can be found here. Take note of a few things:
- Javadocs are begun with /** and ended with */.
- Every class you write must be Javadocd and the @author and @verion tag included. The comments for a class should start with a brief description of the role of the class in your program.
- Every non-private method you write must be Javadocd and the @param tag included for every method parameter. The format for an @param tag is @param <name of parameter as written in method header> <description of parameter>. If the method has a non-void return type, include the @return tag which should have a simple description of what the method returns, semantically.
Reviews
There are no reviews yet.