Package student.micro.battleship
Enum ShipType
- All Implemented Interfaces:
Serializable
,Comparable<ShipType>
,java.lang.constant.Constable
An enumeration representing the five types of ships in a player's fleet
in the game "Battleship".
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>
-
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionRepresents a Battleship, which is 4 units long.Represents an Aircraft Carrier, which is 5 units long.Represents a Destroyer, which is 3 units long.Represents a Patrol Boat, which is 2 units long.Represents a Submarine, which is 3 units long. -
Method Summary
Modifier and TypeMethodDescriptionint
Get the length of this type of ship.static ShipType
valueOf
(int ordinal) Get the ship value corresponding to the specified ordinal value.static ShipType
Returns the enum constant of this type with the specified name.static ShipType[]
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, describeConstable, equals, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
-
Enum Constant Details
-
CARRIER
Represents an Aircraft Carrier, which is 5 units long. -
BATTLESHIP
Represents a Battleship, which is 4 units long. -
SUBMARINE
Represents a Submarine, which is 3 units long. -
DESTROYER
Represents a Destroyer, which is 3 units long. -
PATROL
Represents a Patrol Boat, which is 2 units long.
-
-
Method Details
-
values
Returns an array containing the constants of this enum type, in the order they are declared.- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
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:
IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is null
-
getLength
public int getLength()Get the length of this type of ship.- Carriers are 5 cells long.
- Battleships are 4 cells long.
- Submarines are 3 cells long.
- Destroyers are 3 cells long.
- Patrol boats are 2 cells long.
- Returns:
- This ship type's length.
-
valueOf
Get the ship value corresponding to the specified ordinal value. Use the methodordinal()
to get the ordinal value from an enumeration type (a built-in method for all enums).- CARRIER : 0
- BATTLESHIP : 1
- SUBMARINE : 2
- DESTROYER : 3
- PATROL : 4
- Parameters:
ordinal
- A value from 0-4 indicating the desired ship type.- Returns:
- The ship type that corresponds to the specified numeric value.
-