Class CurrencyService

java.lang.Object
com.csse3200.game.services.CurrencyService

public class CurrencyService extends Object
Service for managing in-level currency.
  • Constructor Summary

    Constructors
    Constructor
    Description
    CurrencyService(int initialAmount, int maxAmount)
    Creates a new currency service with the specified initial amount and maximum limit.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(int amount)
    Adds a positive amount to the currency.
    boolean
    canAfford(int amount)
    Checks if the specified amount is affordable.
    int
    get()
    Gets the currency amount.
    void
    set(int amount)
    Sets the currency amount.
    boolean
    spend(int amount)
    Attempts to spend the specified amount if affordable.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • CurrencyService

      public CurrencyService(int initialAmount, int maxAmount)
      Creates a new currency service with the specified initial amount and maximum limit.
      Parameters:
      initialAmount - starting currency amount
      maxAmount - maximum currency cap
  • Method Details

    • get

      public int get()
      Gets the currency amount.
      Returns:
      the currency amount
    • set

      public void set(int amount)
      Sets the currency amount.
      Parameters:
      amount - the new amount
    • add

      public void add(int amount)
      Adds a positive amount to the currency.
      Parameters:
      amount - the amount to add
    • spend

      public boolean spend(int amount)
      Attempts to spend the specified amount if affordable.
      Parameters:
      amount - the amount to spend
      Returns:
      true if successful, false if insufficient funds
    • canAfford

      public boolean canAfford(int amount)
      Checks if the specified amount is affordable.
      Parameters:
      amount - the amount to check
      Returns:
      true if affordable, false otherwise