SHARE
TWEET

Untitled

advictoriam Feb 1st, 2019 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.    A coin with a monetary value.
  3. */
  4.  
  5. /*
  6.    TODO: Add a static variable that counts the number of coin objects
  7.    that have been constructed. Add a static method objectCount that
  8.    reports the count.
  9. */
  10.  
  11. public class Coin
  12. {
  13.    public static int count = 0;
  14.    /**
  15.       Constructs a coin.
  16.       @param aValue the monetary value of the coin.
  17.       @param aName the name of the coin
  18.    */
  19.    public Coin(double aValue, String aName)
  20.    {
  21.       value = aValue;
  22.       name = aName;
  23.       count++;
  24.    }
  25.  
  26.    /**
  27.       Gets the coin value.
  28.       @return the value
  29.    */
  30.    public double getValue()
  31.    {
  32.       return value;
  33.    }
  34.  
  35.    /**
  36.       Gets the coin name.
  37.       @return the name
  38.    */
  39.    public String getName()
  40.    {
  41.       return name;
  42.    }
  43.    
  44.    public static int objectCount()
  45.    {
  46.       return count;
  47.    }
  48.    
  49.    /**
  50.       Returns a string representation of the object.
  51.       @return name and value of coin
  52.    */
  53.    public String toString()
  54.    {
  55.       return "Coin[value=" + value + ",name=" + name + "]";
  56.    }
  57.  
  58.    private double value;
  59.    private String name;
  60.    
  61.    public static int check(int dimes, int quarters)
  62.    {
  63.       Coin[] coins = new Coin[dimes + quarters];
  64.       for (int i = 1; i <= dimes; i++)
  65.          coins[i] = new Coin(0.10, "dime");
  66.       for (int i = 1; i <= quarters; i++)
  67.          coins[dimes] = new Coin(0.25, "quarter");
  68.       return Coin.objectCount();
  69.    }
  70. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top