Skip to content

Commit

Permalink
Merge pull request #238 from rexkoh425/A-JunitFix
Browse files Browse the repository at this point in the history
A-JunitFixAge
  • Loading branch information
tkhahns authored Nov 12, 2024
2 parents 5d7e101 + 74ee923 commit 28f3dbe
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/DeveloperGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ transactionData.txt should be created in the data folder as well if it does not

`Test case 3` :

`details` : Adding a user using `add-user /u john /a 16 /c +65 77777777` <br>
`details` : Adding a user using `add-user /u john /a 16 /c 87777777` <br>
`check` : The command should return an error message saying that the age is illegal to drive which is true
for most countries at age of 16. Our legal age is 18 thus changing the age to 18 and above but maximally 100 years old
will work now.
10 changes: 8 additions & 2 deletions src/main/java/customer/Customer.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ public Customer(String customerName, int age, String contactNumber) {
throw CustomerException.invalidCustomerNameException(customerName);
}
// Validate age
if (age <= 17) {
if(age <= 17){
throw CustomerException.invalidAgeException();
}else if(age > 100){
throw CustomerException.invalidMaxAgeException();
}

// Validate contact number format
if (isInvalidContactNumber(contactNumber)) {
throw CustomerException.invalidContactNumberException();
Expand Down Expand Up @@ -56,9 +59,12 @@ public void setCustomerName(String customerName) {
}

public void setAge(int age) {
if (age <= 17) {
if(age <= 17){
throw CustomerException.invalidAgeException();
}else if(age > 100){
throw CustomerException.invalidMaxAgeException();
}

this.age = age;
}

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/exceptions/CustomerException.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ public static CustomerException invalidAgeException(){
return new CustomerException("Illegal driver!! Age should be more than 17!!");
}

public static CustomerException invalidMaxAgeException(){
return new CustomerException("This age is not safe to drive!! Too old!!");
}

/**
* Exception thrown when the customer name already exists (case-insensitive).
*
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/parser/CustomerParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ public static Customer parseIntoCustomer(String userInput) throws CustomerExcept
String customerName = parameterContents[0];
int age = Integer.parseInt(parameterContents[1]);

if(age <= 17 || age > 100){
if(age <= 17){
throw CustomerException.invalidAgeException();
}else if(age > 100){
throw CustomerException.invalidMaxAgeException();
}

String contactNumber = parameterContents[2];
Expand Down

0 comments on commit 28f3dbe

Please sign in to comment.