How can I print error messages from my function when the arguments are invalid?
<p>I just started to learn Java. There is a course in MIT and there is <a href="http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-092-introduction-to-programming-in-java-january-iap-2010/assignments/MIT6_092IAP10_assn02.pdf" rel="nofollow">an assignment</a> to write a class for pay calculation. Part of the task is:</p>

<blockquote>
  <ul>
  <li>The base pay must not be less than the minimum wage ($8.00 an hour). If it is, print an error.</li>
  <li>If the number of hours is greater than 60, print an error message.</li>
  </ul>
</blockquote>

<p>The code I have written is as follows:</p>

<pre><code>public class fooCorporation {
    private float totalPay;
    private float calc;

    public float totalPay(double basePay, int hours){

        if(hours &lt;= 40){
            totalPay = (float) (basePay * hours);
        }
        else if(hours &gt; 40){
            int extraHours =  hours - 40;
            float payForFortyHours = (float) (basePay * hours);
            float payForextraHours = (float) (basePay * 1.5 * extraHours);

            totalPay = payForFortyHours + payForextraHours;
        }
        return totalPay;
    }

    public static void main(String[] args){
        fooCorporation foo = new fooCorporation();
        System.out.println("employee 1: " + foo.totalPay(7.50,35));
        System.out.println("employee 2: " + foo.totalPay(8.20,47));
        System.out.println("employee 3: " + foo.totalPay(10.00,73));
    }
}
</code></pre>

<p>The problem I am facing is how to print an error message from the function <code>totalPay()</code> when some conditions are not met. Can the above logic be written in a different way?</p>
