Monopoly
Class Property

java.lang.Object
  extended by Monopoly.Cell
      extended by Monopoly.Property
All Implemented Interfaces:
Collectable, Interactive
Direct Known Subclasses:
Company, Street, TrainStation

public abstract class Property
extends Cell
implements Collectable

This abstract class represents any cell which can be owned by a player of Monopoly

This class methods manage the bying and the selling of a cell which can by a property

Implementation invariants: the price of the property cell is constant during the game

See Also:
Cell, Interactive, Collectable, Street, Company, TrainStation

Constructor Summary
Property(java.lang.String name, int location, int price)
          Constructs a new cell which can be owned by a player.
 
Method Summary
 void act(Monopoly game)
          Makes a player to buy the property or pay the rent for it.
 Player getOwner()
          Returns the owner of the property cell (Accessor).
 java.lang.String getOwnerName()
          Returns the name of the cell's owner (Accessor).
 int getPrice()
          Returns the price of the property cell (Accessor).
abstract  int getRent()
          Calculates and returns the rent of the property cell that someone must pay if he goes at the exact cell (Accessor).
 boolean ismortaged()
          Returns whether a property is mortaged or not (Accessor).
 void mortage()
          Mortages the property cell (Transformer).
 void setOwner(Player owner)
          Sets the given player as the owner of the property cell (Transformer).
 java.lang.String toString()
          Returns the name of the Property cell (Accessor).
 void unmortage()
          Unmortages the property cell (Transformer).
 
Methods inherited from class Monopoly.Cell
getLocation, getName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Property

public Property(java.lang.String name,
                int location,
                int price)
Constructs a new cell which can be owned by a player.

Method Detail

getPrice

public int getPrice()
Returns the price of the property cell (Accessor).

Pre: true
Post: returns the price of the property cell

Returns:
The price of the property cell (int)

getRent

public abstract int getRent()
Calculates and returns the rent of the property cell that someone must pay if he goes at the exact cell (Accessor).

Pre: true
Post: always returns the rent consulting some parameters of the specific property cell

Returns:
The rent to be paid (int)

ismortaged

public boolean ismortaged()
Returns whether a property is mortaged or not (Accessor).

Pre: true
Post: true

Returns:
The condition of the Property cell (boolean)

getOwner

public Player getOwner()
Returns the owner of the property cell (Accessor).

Pre: true
Post: the returned player might be null if the owner of the cell is the bank

Specified by:
getOwner in interface Collectable
Returns:
The owner of the property cell (Player)
- or null if the owner is the bank

getOwnerName

public java.lang.String getOwnerName()
Returns the name of the cell's owner (Accessor).

Pre: true
Post: if there is no owner, the returned name is "Bank"

Returns:
The owner's name (String)

toString

public java.lang.String toString()
                          throws java.lang.NullPointerException
Returns the name of the Property cell (Accessor).

Pre: true
Post: Returns a name which is different than null

Overrides:
toString in class java.lang.Object
Returns:
The name of the Property (String)
Throws:
java.lang.NullPointerException

mortage

public void mortage()
Mortages the property cell (Transformer).

Pre: true
Post: sells the property cell to bank for the half price.


unmortage

public void unmortage()
Unmortages the property cell (Transformer).

Pre: the property cell must be mortaged
Post: buys the property cell from the bank for the half price.


setOwner

public void setOwner(Player owner)
Sets the given player as the owner of the property cell (Transformer).

Pre: true
Post: the given player becomes the owner of the property cell

Specified by:
setOwner in interface Collectable
Parameters:
owner - The player who will be the owner

act

public void act(Monopoly game)
Makes a player to buy the property or pay the rent for it.
Pre: the game must be different than null
Post: true

Specified by:
act in interface Interactive
Overrides:
act in class Cell
Parameters:
game - the Monopoly instance that represents the game.