Question
Java Program Please, please follow the instructions exactly and include detailed comments so I may understand. I need help with the Directions and the DirectionTest;
Java Program
Please, please follow the instructions exactly and include detailed comments so I may understand.
I need help with the Directions and the DirectionTest; I have already created the properties files it speaks of (n.properties, s.properties, etc) in a resource file in my project CollosalCaveAdventure- as well as its packages that are given (edu.waketech.ccave, edu.waketech.ccave.common, edu.waketech.ccave.item,edu.waketech.ccave.location, edu.waketech.ccave.provided, edu.waketech.ccave.test, edu.waketech.ccave.utility).
.Direction Enum Specs:
Enum Direction
java.lang.Object
java.lang.Enum
edu.waketech.ccave.common.Direction
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable
public enum Direction extends java.lang.Enum
All possible directions that a player can travel. We read a properties file to determine the synonyms for each direction. This enum reads a properties file for each enum value in the resources directory, such as
n.properties
s.properties
etc.
Enum Constant and Description |
---|
DOWN |
E |
N |
NE |
NW |
S |
SE |
SW |
UNKNOWN |
UP |
W |
Field Summary
Modifier and Type | Field and Description |
---|---|
static java.lang.String | RESOURCE_DIR |
Method Summary
Modifier and Type | Method and Description |
---|---|
static Direction | findSynonym(java.lang.String possibleAlt) enum-wide method to provide a more friendly valueOf method. |
boolean | isSynonym(java.lang.String possibleAlt) Determine whether a given String value represents this Direction value ignoring case, or one of its synonyms ignoring case. |
static Direction | valueOf(java.lang.String name) Returns the enum constant of this type with the specified name. |
static Direction[] | values() Returns an array containing the constants of this enum type, in the order they are declared. |
Methods inherited from class java.lang.Enum
compareTo, equals, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
Enum Constant Detail
N
public static final Direction N
S
public static final Direction S
E
public static final Direction E
W
public static final Direction W
NE
public static final Direction NE
NW
public static final Direction NW
SE
public static final Direction SE
SW
public static final Direction SW
UP
public static final Direction UP
DOWN
public static final Direction DOWN
UNKNOWN
public static final Direction UNKNOWN
Field Detail
RESOURCE_DIR
public static final java.lang.String RESOURCE_DIR
See Also:
Constant Field Values
Method Detail
values
public static Direction[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
for (Direction c : Direction.values()) System.out.println(c);
Returns:
an array containing the constants of this enum type, in the order they are declared
valueOf
public static Direction valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
Parameters:
name - the name of the enum constant to be returned.
Returns:
the enum constant with the specified name
Throws:
java.lang.IllegalArgumentException - if this enum type has no constant with the specified name
java.lang.NullPointerException - if the argument is null
findSynonym
public static Direction findSynonym(java.lang.String possibleAlt)
enum-wide method to provide a more friendly valueOf method. We take a String representation of an enum value or synonym and, ignoring case, return the corresponding Direction enum value. This method steps through every possible enum value, which it can do using values(). It then tests whether possibleAlt matches one of those values. (See isSynonym)
Parameters:
possibleAlt - String representing a case-insensitive, synonym-based Direction value
Returns:
the Direction value associated with possibleAlt, or Direction.UNKNOWN
isSynonym
public boolean isSynonym(java.lang.String possibleAlt)
Determine whether a given String value represents this Direction value ignoring case, or one of its synonyms ignoring case.
Parameters:
possibleAlt - a possible String representation of this Direction or one of its synonym values
Returns:
true if possibleAlt is a valid String value for this Direction or one of its synonyms, all ignoring case
Points to remember for this:
1: Create an enum in the edu.waketech.ccave.common package called Direction. This enum has the following values: N, S, E, W, NE, NW, SE, SW, UP, DOWN, UNKNOWN.
2: In the resources directory, create a properties file for each direction except UNKNOWN. For example, resources will contain a file n.properties. This file will contain a series of synonyms for Direction.N, where the property key is meaningless and the property value is a synonym for N, for example, "north". So n.properties would have at least one line n=north (I have done this already but I do need the Direction to call from it in the code)
3: The Direction enum has an instance variable of type ArrayList that holds the enum's given synonyms from the corresponding properties file information.
4: The Direction enum's constructor reads the associated properties file from the resources directory and adds the synonyms to the ArrayList instance variable.
..............................................................................................................
DirectionTest Specs:
Class DirectionTest
java.lang.Object
edu.waketech.ccave.test.DirectionTest
public class DirectionTest extends java.lang.Object
JUnit test for Direction. This is a minimal skeleton for testing Direction; hopefully your tests will be more thorough.
Author:
parks
Constructor Summary
Constructor and Description |
---|
DirectionTest() |
Method Summary
Modifier and Type | Method and Description |
---|---|
void | testEquals() This test is just to verify my understanding of enums. |
void | testIsSynonym() Test that Direction.findSynonym("north") returns Direction.N |
void | testIsSynonym0() Test that Direction.findSynonym("misspelled") returns Direction.UNKNOWN |
void | testIsSynonym1() Test that Direction.findSynonym("n") returns Direction.N |
void | testIsSynonym2() Test that Direction.findSynonym("down") returns Direction.DOWN |
void | testIsSynonym3() Test that Direction.findSynonym("d") returns Direction.DOWN |
void | testIsSynonym4() Test that Direction.N.isSynonym("North") is true |
void | testIsSynonym5() Test that Direction.N.isSynonym("south") is false |
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Constructor Detail
DirectionTest
public DirectionTest()
Method Detail
testIsSynonym
public void testIsSynonym()
Test that Direction.findSynonym("north") returns Direction.N
testIsSynonym0
public void testIsSynonym0()
Test that Direction.findSynonym("misspelled") returns Direction.UNKNOWN
testIsSynonym1
public void testIsSynonym1()
Test that Direction.findSynonym("n") returns Direction.N
testIsSynonym2
public void testIsSynonym2()
Test that Direction.findSynonym("down") returns Direction.DOWN
testIsSynonym3
public void testIsSynonym3()
Test that Direction.findSynonym("d") returns Direction.DOWN
testIsSynonym4
public void testIsSynonym4()
Test that Direction.N.isSynonym("North") is true
testIsSynonym5
public void testIsSynonym5()
Test that Direction.N.isSynonym("south") is false
testEquals
public void testEquals()
This test is just to verify my understanding of enums. It tests that Direction.N.toString().equalsIgnoreCase("n") is true.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started