Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private String normalizeDiscountCode(String discountCode) {
- int index = 0; // create variable to hold the loop count / index
- while(index < discountCode.length()) { // loop until the index is less than the discountCode length
- char code = discountCode.charAt(index); // use the index to pull out the appropriate char
- if(!Character.isLetter(code) || code != '$' ){
- throw new IllegalArgumentException("Invalid discount");
- }
- index++; // increase the index so that during the next loop we pull out the next character, and to make sure the loop eventually ends.
- }
- discountCode = discountCode.toUpperCase();
- return discountCode;
- }
Advertisement
Add Comment
Please, Sign In to add comment