-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathStringLogic.java
More file actions
25 lines (20 loc) · 988 Bytes
/
StringLogic.java
File metadata and controls
25 lines (20 loc) · 988 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package org.codedifferently;
public class StringLogic {
//generates a receipt code after receiving the first and lastName. takes the first 3 letters
//of both to include with a randomly generated number
public String generateReceiptCode(String firstName, String lastName) {
String firstNameTruncate = (firstName.length() > 3) ? firstName.substring(0,3) : firstName;
String lastNameTruncate = (lastName.length() > 3) ? lastName.substring(0,3) : lastName;
String nameTruncated = firstNameTruncate + lastNameTruncate;
MathCalc matchCalc = new MathCalc();
int randomNum = matchCalc.generateRandomNumber(10,100);
return nameTruncated + randomNum;
}
//validates coupon code, returns true if it starts with a c and contains a -
public boolean checkValidCoupon(String couponCode) {
if (couponCode.startsWith(("c")) && couponCode.contains("-")) {
return true;
}
return false;
}
}