All pastes #499146 Raw Edit

Unnamed

public java v1 · immutable
·published 2007-05-20 22:11 UTC
rendered paste body
//Boat Inventory Program//Author: Rayno Niemi//Purpose:  Definition of a Boat class with color and lengthpublic abstract class Boat implements BoatConstants{	    private String colour;	//color of boat    private int    len;		//length of boat        //valid boat colors    final private static String[] BOAT_COLOR = {"white", "red", "blue"};        /**      *Creates a default Boat     */	public Boat( ) 	{		//create a boat with default color and length	 		this(BOAT_COLOR[0], 10);	}        /**      *Creates a new instance of Boat     *@param colour - color of boat     *@param len    - length of boat      */	public Boat(String colour, int len) 	{		if (!setColor(colour))		{	//invalid color - set to default			this.colour = BOAT_COLOR[0];		}		if (!setLength(len))		{	//invalid length - set to default			this.len = 10;		}	}        /**      *Get color of boat     *@returns color of the boat as a String     */	public String getColor()	{		return colour;	}        /**      *set color of boat     *@param colour - new colour for boat     *@returns true if color is valid; otherwise false     */	public boolean setColor(String colour)	{		//check parameter value with list of valid colors		for (int k=0; k < BOAT_COLOR.length; k++)		{			if ( colour.equals(BOAT_COLOR[k]) )			{	//valid color found				this.colour = colour;				return true;			}		}		//invalid color - do not change color		return false;   	}        /**      *Get length of boat     *@returns length of boat as an int     */	public double getLength()	{		return this.len;	}        /**      *set length of boat - must be 10 feet or greater     *@param len - new len for boat     *@returns true if len is valid; otherwise false     */	public boolean setLength(int len)	{		if (len >= 10)		{	//valid length			this.len = len;			return true;		}		else		{	//invalid length			return false; 		}  	}        /**     *Convert boat into a string with attribute values     *@return String with color and length     */	public String toString( )	{		return "Color: " + getColor() + " Length: " + getLength();	}     }//end class