title: Problem with class creation specific to the below problem
body: <p>I have a problem in a Java coding problem, and I could use a little bit of help in understanding the thought process of a condition mentioned in the problem (highlighted below).</p>
  <p>The goal of this question is to design a cash register program. Your register currently has the following notes/coins within it:</p>
  <p>One Pence: .01
  Two Pence: .02
  Five Pence: .05
  Ten Pence: .10
  Twenty Pence: .20
  Fifty Pence: .50
  One Pound: 1
  Two Pounds: 2
  Five Pounds: 5
  Ten Pounds: 10
  Twenty Pounds: 20
  Fifty Pounds: 50</p>
  <p>The aim of the program is to calculate the change that has to be returned to the customer with the least number of coins/notes. Note that the expectation is to have an object-oriented solution - <strong>think about creating classes for better reusability</strong>.</p>
  <p>Now there is a similar post for this question on this platform, but I want to know how to use classes in this problem instead of hardcoding the denominations? I would highly appreciate if anyone can shed some light on it! I have written the following code for this, any help on changing this according to the condition above will be appreciated:</p>
  <pre><code>    import java.io.BufferedReader;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.nio.charset.StandardCharsets;
  import java.io.*;
  
  public class Main {
    /**
     * Iterate through each line of input.
     */
    public static void main(String[] args) throws IOException {
      InputStreamReader reader = new InputStreamReader(System.in);
      BufferedReader in = new BufferedReader(reader);
  
      try {
          double purchasePrice = Double.parseDouble(in.readLine());
          double cash = Double.parseDouble(in.readLine());
          Main.calculateChange(purchasePrice, cash);
      } catch (Exception e) {
          System.out.println(e);
      }
    }
  
    public static void calculateChange(double purchasePrice, double cash) {
      
      float cashBack = (float) (cash - purchasePrice);
      
      if (cashBack &lt; 0) {
        System.out.println(&quot;ERROR&quot;);
        return ;
      }
      else if (cashBack == 0){
        System.out.println(0);
      }
      StringBuilder change = new StringBuilder();
  
          while (cashBack &gt; 0.01) {
              if (cashBack &gt;= 50.0) {
                  change.append(&quot;Fifty Pounds&quot;);
                  cashBack -= 50.0;
              } else if (cashBack &gt;= 20.0) {
                  change.append(&quot;Twenty Pounds&quot;);
                  cashBack -= 20.0; 
              } else if (cashBack &gt;= 10.0) {
                  change.append(&quot;Ten Pounds&quot;);
                  cashBack -= 10.0;
              } else if (cashBack &gt;= 5.0) {
                  change.append(&quot;Five Pounds&quot;);
                  cashBack -= 5.0;
              } else if (cashBack &gt;= 2.0) {
                  change.append(&quot;Two Pounds&quot;);
                  cashBack -= 2.0;
              } else if (cashBack &gt;= 1.0) {
                  change.append(&quot;One Pound&quot;);
                  cashBack -= 1.0;
              } else if (cashBack &gt;= 0.5) {
                  change.append(&quot;Fifty Pence&quot;);
                  cashBack -= 0.5;
              } else if (cashBack &gt;= 0.20) {
                  change.append(&quot;Twenty Pence&quot;);
                  cashBack -= 0.20;
              } else if (cashBack &gt;= 0.1) {
                  change.append(&quot;Ten Pence&quot;);
                  cashBack -= 0.1;
              } else if (cashBack &gt;= 0.05) {
                  change.append(&quot;Five Pence&quot;);
                  cashBack -= 0.05;
              } else if (cashBack &gt;= 0.02) {
                  change.append(&quot;Two Pence&quot;);
                  cashBack -= 0.02;
              } else {
                  change.append(&quot;One Pence&quot;);
                  cashBack -= 0.01;
              }
              change.append(&quot;, &quot;);
          }
          change.setLength(change.length() - 2);
  
          System.out.println(change.toString());
      // Access your code here. Feel free to create other classes as required
    }
  
  }
  </code></pre>