Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[T2A4][W10-A2]Lee Yi Min #128

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
270 changes: 92 additions & 178 deletions src/seedu/addressbook/AddressBook.java

Large diffs are not rendered by default.

90 changes: 90 additions & 0 deletions src/seedu/addressbook/Person.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/**
*
*/
package seedu.addressbook;

/**
* @author YiMin
*
*/
public class Person {
private static final String PERSON_STRING_REPRESENTATION = "%1$s " // name
+ AddressBook.PERSON_DATA_PREFIX_PHONE + "%2$s " // phone
+ AddressBook.PERSON_DATA_PREFIX_EMAIL + "%3$s"; // email

private final String name_;
private final String email_;
private final String phone_;

public Person(String name, String phone, String email){
name_=name;
phone_=phone;
email_=email;
}

/**
* @return the name_
*/
public String getName() {
return name_;
}

/**
* @return the email_
*/
public String getEmail() {
return email_;
}

/**
* @return the phone_
*/
public String getPhone() {
return phone_;
}

/**
* Validates the person's data fields
*
* @return whether the person has valid data
*/
public boolean isValid() {
return isNameValid() && isPhoneValid() && isEmailValid();
}

/**
* Validates name as a legal person name
*
* @return whether name is a valid person name
*/
private boolean isNameValid() {
return name_.matches("(\\w|\\s)+"); // name is nonempty mixture of alphabets and whitespace
//TODO: implement a more permissive validation
}

/**
* Validates phone as a legal person phone number
*=
* @return whether phone is a valid person phone number
*/
private boolean isPhoneValid() {
return phone_.matches("\\d+"); // phone nonempty sequence of digits
//TODO: implement a more permissive validation
}

/**
* Validates email as a legal person email
*
* @return whether email is a valid person email
*/
private boolean isEmailValid() {
return email_.matches("\\S+@\\S+\\.\\S+"); // email is [non-whitespace]@[non-whitespace].[non-whitespace]
//TODO: implement a more permissive validation
}

@Override
public String toString(){
return String.format(PERSON_STRING_REPRESENTATION,
name_,email_,phone_);
}
}
2 changes: 1 addition & 1 deletion test/runtests.bat
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@ECHO OFF
REM compile the code into the bin folder
javac ..\src\seedu\addressbook\Addressbook.java -d ..\bin
javac ..\src\seedu\addressbook\Addressbook.java ..\src\seedu\addressbook\Person.java -d ..\bin

REM run the program, feed commands from input.txt file and redirect the output to the actual.txt
java -classpath ..\bin seedu.addressbook.AddressBook < input.txt > actual.txt
2 changes: 1 addition & 1 deletion test/runtests.sh
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ then
fi

# compile the code into the bin folder
javac ../src/seedu/addressbook/AddressBook.java -d ../bin
javac ../src/seedu/addressbook/AddressBook.java ../src/seedu/addressbook/Person.java -d ../bin

# run the program, feed commands from input.txt file and redirect the output to the actual.txt
java -classpath ../bin seedu.addressbook.AddressBook < input.txt > actual.txt