public void sendSMS(String sourceNumber, String destinationNumber, String message) { if (message == null) throw new SMSInvalidTextException(sourceNumber, destinationNumber); Phone senderPhone = this.getPhone(sourceNumber); boolean sameOperator = sameOperator(sourceNumber, destinationNumber); int smsCost = senderPhone.getOperator().getPlan().calcCostSMS(message, sameOperator); senderPhone.checkCostAndBalance(smsCost); senderPhone.decreaseBalanceBy(smsCost); SMS sms = new SMS(sourceNumber, destinationNumber, message, smsCost); senderPhone.addSentSMS(sms); }
public void endSourceVoiceCall( String sourcePhoneNumber, String destinationPhoneNumber, int duration) { if (duration < 0) throw new InvalidDurationException(sourcePhoneNumber, destinationPhoneNumber); Phone sourcePhone = getPhone(sourcePhoneNumber); Voice activeCommunication = (Voice) sourcePhone.checkActiveCommunication( sourcePhoneNumber, destinationPhoneNumber, AnacomData.CommunicationType.VOICE); boolean sameOperator = sameOperator(sourcePhoneNumber, destinationPhoneNumber); int cost = sourcePhone.getOperator().getPlan().calcCostVoice(duration, sameOperator); sourcePhone.decreaseBalanceBy(cost); activeCommunication.setCost(cost); activeCommunication.setDuration(duration); sourcePhone.endSentVoiceCall(activeCommunication); }