advictoriam

Untitled

Feb 1st, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.11 KB | None | 0 0
  1. /**
  2.    Calculate the salary amount by applying a bonus rate.
  3. */
  4.  
  5. public class SalaryBonus
  6. {
  7.    private double salary;
  8.    private double bonusRate;
  9.  
  10.    public SalaryBonus(double aSalary, double aRate)
  11.    {
  12.       assert(aSalary <= 150000);
  13.       assert(aRate <= 0.05);
  14.       salary = aSalary;
  15.       bonusRate = aRate;
  16.    }
  17.    
  18.    /**
  19.       The following method checks your constructor. We use the exception
  20.       handling mechanism (see chapter 11) to determine whether (a) the
  21.       constructor completed normally, (b) your code used an assertion to
  22.       check a precondition violation, or (c) you failed to use an
  23.       assertion and some other exception occurred.
  24.    */  
  25.    public static String check(double salaryTest, double rateTest)
  26.    {
  27.       try
  28.       {
  29.          SalaryBonus eBonus = new SalaryBonus(salaryTest,rateTest);
  30.          return "Constructor completed normally";
  31.       }
  32.       catch (AssertionError error)
  33.       {
  34.          return "Precondition violation detected";
  35.       }
  36.       catch (Exception exception)
  37.       {
  38.          return "Exception in constructor";
  39.       }
  40.    }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment