I am writing a program related to rowing and I am creating an immutable class called "BoatType" to represent the various "types" of boats that are. This becomes complicated because there are many types that require a unique description.
A BoatType must have the following:
- Either type SCULL or SWEEP
- A number that matches the number of people who fit into the boat
- Type PORT or STARBOARD, but only if the first type is SWEEP
- Boolean representing COXED or UNCOXED, usually only for SWEEP
This is further complicated by the fact that only certain combinations of these fields exist in the rowing world. I want my program to have easy access to these standard types without the need to create new BoatType objects. This, in full:
Scully 8
SCULL 4
SCULL 2
SCULL 1
SWEEP 8 COXED PORT
SWEEP 8 COXED STARBOARD
SWEEP 4 COXED PORT
SWEEP 4 UNCOXED PORT
SWEEP 4 COXED STARBOARD
SWEEP 4 STARBOARD UNCOXED
SWEEP 2 COXED PORT
SWEEP 2 UNCOXED PORT
SWEEP 2 COXED STARBOARD
SWEEP 2 STARBOARD UNCOXED
This is currently a class that I wrote in Java:
public class BoatType
{
public enum RiggerType{SCULL, SWEEP_PORT, SWEEP_STARBOARD}
private int numSeats;
private RiggerType riggerType;
public boolean coxswain = true;
public BoatType(RiggerType type, int seats, boolean coxed)
{
numSeats = seats;
riggerType = type;
coxswain = coxed;
}
}
listing standard types elsewhere:
public static final BoatType
SCULL_OCTUPLE = new BoatType(RiggerType.SCULL, 8, false),
SCULL_QUAD = new BoatType(RiggerType.SCULL, 4, false),
SCULL_DOUBLE = new BoatType(RiggerType.SCULL, 2, false),
SCULL_SINGLE = new BoatType(RiggerType.SCULL, 1, false),
SWEEP_PORT_EIGHT_COXED = new BoatType(RiggerType.SWEEP_PORT, 8, true),
SWEEP_STARBOARD_EIGHT_COXED = new BoatType(RiggerType.SWEEP_STARBOARD, 8, true),
SWEEP_PORT_FOUR_COXED = new BoatType(RiggerType.SWEEP_PORT, 4, true),
SWEEP_PORT_FOUR_UNCOXED = new BoatType(RiggerType.SWEEP_PORT, 4, false),
SWEEP_STARBOARD_FOUR_COXED = new BoatType(RiggerType.SWEEP_STARBOARD, 4, true),
SWEEP_STARBOARD_FOUR_UNCOXED = new BoatType(RiggerType.SWEEP_STARBOARD, 4, false),
SWEEP_PORT_PAIR_COXED = new BoatType(RiggerType.SWEEP_PORT, 2, true),
SWEEP_PORT_PAIR_UNCOXED = new BoatType(RiggerType.SWEEP_PORT, 2, false),
SWEEP_STARBOARD_PAIR_COXED = new BoatType(RiggerType.SWEEP_STARBOARD, 2, true),
SWEEP_STARBOARD_PAIR_UNCOXED = new BoatType(RiggerType.SWEEP_STARBOARD, 2, false);
, , - , . , , , .