Viewing file: comp249/assignment1/Widget.java | Back to directory listing
Author: Loren Segal | Last modified: February 21 2006 12:00 am | Download

 
/**
 * Abstract class Widget - Basic entity of the BGD infrastructure
 * 
 * @author Loren Segal
 * @version 1.0
 */
public abstract class Widget
{
    private String name;
    
    /**
     * Creates a widget with a name
     */      
    public Widget(String newName)
    {
        setName(newName);
    }
 
    /**
     * Gets the name of the Widget
     * 
     * @return  the widget name
     */
    public String getName()
    {
        return this.name;
    }
 
    /**
     * Sets the name of the Widget
     * 
     * @param   newName     the name of the widget
     */
    public void setName(String newName)
    {
        this.name = newName;
    }
 
    /**
     * Gets the price of the Widget, must be overridden
     * 
     * @return  the widget price
     */
    public abstract double calculatePrice();
 
    /**
     * The object's string representation
     * 
     * @return  A string of form: "NAME: PRICE"
     */
    public String toString()
    {
        return "** Big Green Dog Corp **\n" +
            getName() + ": " + calculatePrice() + "\n";
    }
}