~cpp if (data.before( SUMMER_START ) || data.after(SUMMER_END) ) charge = quantity * _winterRate + _winterServeceCharge; else charge = quantity * _summerRate;
~cpp if (notSummer(date)) charge = winterCharge(quantity); else charge = summerCharge(quatity);
~cpp double disabilityAmount() { if (_seniority < 2) return 0; if ( _monthsDisabled > 12) return 0; if ( _isPartTime) return 0; // compute the disability amount
~cpp double disabilityAmount() { if( isNotEligableForDisability()) return 0; // compute the disability amount;
~cpp if (isSpecialDeal()){ total = price * 0.95; send(); } else { total = price * 0.98; send(); }
~cpp if (isSpecialDeal()) total = price * 0.95 else total = price * 0.98; send();
~cpp double getPayAmount(){ double result; if( _isDead) result = deadAmount(); else { if (_isSeparated) result = separatedAmount(); else { if (_isRetried) result = retiredAmount(); else result = normalPayAmount(); }; } return result;
~cpp double getPayAmount() { if (_isDead) return deadAmount(); if (_isSeparated) return separatedAmount(); if (_isRetried) return retiredAmount(); return normalPayAmount();
~cpp double getSpeed() { switch (_type) { case EUROPEAN: return getBaseSpeed(); case AFRICAN: return getBaseSpeed() - getLoadFactor() * _numberofCoconuts; case NORWEGIAN_BLUE: return (_isNailed) ? 0 : getBaseSpeed(_voltage); } throw new RuntimeException ("Should be unreachable"); }
~cpp ┌─────┐ │ Bird │ ├─────┤ │getSpeed │ └─────┘ △ │ ┌───────┼─────────┐ │ │ │ ┌──┴──┐ ┌──┴──┐ ┌────┴──┐ │European| │ │African │ │Norwegian Blue│ ├─────┤ ├─────┤ ├───────┤ │getSpeed │ │getSpeed │ │getSpeed │ └─────┘ └─────┘ └───────┘
~cpp if (customer == null) plan = BillingPlan.basic(); else plan = customer.getPlan();
~cpp ┌───────┐ │ Cutomer │ ├───────┤ │getPlan │ └───────┘ △ │ ┌───┴───┐ │Null Customer │ ├───────┤ │getPlan │ └───────┘
~cpp double getExpenseLimit() { //should have eigher expense limit or a primary project return (_expenseLimit != NULL_EXPENSE)? _expenseLimit: _primaryProject.getMemberExpenseLimit(); }
~cpp double getExpenseLimit() { Assert.isTrue( _expenseLimit != NULL_EXPENSE || _primaryProject != null ); return (_expenseLimit != NULL_EXPENSE)? _expenseLimit: _primaryProject.getMemberExpenseLimit();