Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Make a constructor <code>private</code> to prevent instances of the class from being made outside the class. Else make it public to allow instances of the class to be created anywhere from where the class is visible.</p> <p>Hence, your <code>Constructor</code> has to be <strong>public</strong>, so that you can instantiate it in your <code>SoftwareSalesTester</code> class.</p> <p>Hence, <code>public SoftwareSaleClass (double q)</code>.</p> <p>Next, <code>quantity = q;</code> is placed inside the constructor so that you can assign some value to it, when you create a new <code>SoftwareSaleClass</code> object. If not from where else do you intend to set its value, to be used in your <code>getYourTotal()</code> method.</p> <pre><code>public double getQuantity() { return quantity; // Does this need to be here? If so why? I never use it in the tester class or do I? } </code></pre> <p>You may or may not have this method, depending on your needs. Since you don't use it in your test class, you may not need it now, but may be somewhere else, sometime later, you may need it. Hence, this method will return your <code>private</code> variable <code>quantity</code> which cannot be accessed otherwise.</p> <p>Not really sure what you meant by the below statement.</p> <pre><code>} // This part I totally understand the why, although I think my math isn't quite right. } </code></pre> <p>And finally, <code>double quantity;</code> in your <code>SoftwareSalesTester</code> class has nothing to do with the <code>quantity</code> in your <code>SoftwareSaleClass</code>. You can name it anything you want.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload