Skip to content

Commit

Permalink
Debug find friend command
Browse files Browse the repository at this point in the history
  • Loading branch information
xxzz-tt committed Sep 16, 2020
1 parent 1859519 commit b468f91
Show file tree
Hide file tree
Showing 15 changed files with 281 additions and 63 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ test {
}

application {
mainClassName = "seedu.duke.Duke"
mainClassName = "Duke"
}

shadowJar {
Expand Down
24 changes: 3 additions & 21 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ command line instructions to interact with the users.
6. Display the existing list of tasks
7. Add a new friend to the friend list
8. Delete an existing friend from your friend list
9. Update the information of a friend in your friend list
10. Display the existing list of friends
9. Display the existing list of friends

### Feature 1
Add a new task to the current task list. A new task can be a ToDo, Deadline
Expand All @@ -39,8 +38,6 @@ Add a new friend to the current friend list
### Feature 8
Delete a friend from the current friend list
### Feature 9
Update the information of a friend (e.g. name, phone number, relationship status) in your current friend list
### Feature 10
Display an entire list of friends
## Usage

Expand Down Expand Up @@ -166,7 +163,7 @@ Delete a friend in the friend list based on its index in the list

Example of usage:

`delete 1`
`fdelete 1`

Expected outcome:

Expand All @@ -182,19 +179,4 @@ Expected outcome:
```
Here are all your friends:
1. Charles (number: 91234567, isClose: true)
```

### `update <index> /phone number <new phone number>` - Update information of a particular friend

Update the phone number of the friend based on the index in the friend list

Example of usage:

`update 2 /phone number 81234567`

Expected outcome:

```
Update the info of Bella:
1. Belle (number: 81234567, isClose: false)
```
```
48 changes: 48 additions & 0 deletions src/main/java/AddFriendCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import java.io.IOException;

public class AddFriendCommand extends Command{

private Friend friend;

/**
* Constructor for the class.
* @param friend
*/
public AddFriendCommand(Friend friend) {
this.friend = friend;
}

/**
* Generate a list of tasks to user.
* @param friends
* @param ui
* @param storage
* @return a String to reply user.
* @throws IOException
*/
public String execute(FriendList friends, Ui ui, Storage storage) throws IOException {
friends.add(friend);
return ui.addFriend(this.friend);
}

/**
* Empty execution.
* @param tasks
* @param ui
* @param storage
* @return null value as there is no tasks
* @throws IOException
*/
@Override
public String execute(TaskList tasks, Ui ui, Storage storage) throws IOException {
return null;
}

/**
* To check if the command is an exit command
* @return a false
*/
public boolean isExit() {
return false;
}
}
49 changes: 49 additions & 0 deletions src/main/java/DeleteFriendCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import java.io.IOException;

public class DeleteFriendCommand extends Command {

private int i;

/**
* Constructor for the class.
* @param i
*/
public DeleteFriendCommand(int i) {
this.i = i;
}

/**
* Generate a list of tasks to user.
* @param friends
* @param ui
* @param storage
* @return a String to reply user.
* @throws IOException
*/
public String execute(FriendList friends, Ui ui, Storage storage) throws IOException {
Friend deletedFriend = friends.getList().get(this.i - 1);
friends.delete(this.i - 1);
return ui.deleteFriend(deletedFriend);
}

/**
* Empty execution.
* @param tasks
* @param ui
* @param storage
* @return null value as there is no tasks
* @throws IOException
*/
@Override
public String execute(TaskList tasks, Ui ui, Storage storage) throws IOException {
return null;
}

/**
* To check if the command is an exit command
* @return a false
*/
public boolean isExit() {
return false;
}
}
23 changes: 13 additions & 10 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public Duke(String filePath) {
this.friendList = new FriendList();
try {
taskList = new TaskList(storage.loadData());
} catch (Exception e) {
} catch (Exception | IncorrectInputException e) {
System.out.println("tasklist not loaded");
}
}
Expand All @@ -33,7 +33,7 @@ public Duke() {
this.friendList = new FriendList();
try {
taskList = new TaskList(storage.loadData());
} catch (Exception e) {
} catch (Exception | IncorrectInputException e) {
e.printStackTrace();
}
}
Expand All @@ -43,7 +43,7 @@ public Duke() {
* @throws IOException
* @throws IncorrectInputException
*/
public void run() throws IOException, IncorrectInputException {
public void run() throws IncorrectInputException {
ui.greeting();
boolean isExit = false;
while (!isExit) {
Expand All @@ -53,9 +53,9 @@ public void run() throws IOException, IncorrectInputException {
Command c = Parser.parse(fullCommand);
c.execute(taskList, ui, storage);
isExit = c.isExit();
} catch (IOException e) {
System.out.println(e.getMessage());
// ui.showError(e.getMessage());
} catch (Exception e) {
// System.out.println(e.getMessage());
e.printStackTrace();
} finally {
ui.showLine();
}
Expand All @@ -69,10 +69,13 @@ public void run() throws IOException, IncorrectInputException {
* @throws IOException
* @throws IncorrectInputException
*/
public String getResponse(String input) throws IOException, IncorrectInputException {
Command c = Parser.parse(input);
// return c.execute();
return c.execute(this.taskList, this.ui, this.storage);
public String getResponse(String input) {
try {
Command c = Parser.parse(input);
return c.execute(this.taskList, this.ui, this.storage);
} catch (IncorrectInputException | EmptyInputException | IOException e) {
return e.getMessage();
}
}

public static void main(String[] args) throws IOException, IncorrectInputException {
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/EmptyInputException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public class EmptyInputException extends Exception {

public EmptyInputException(String e) {
super("☹ OOPS!!! The description of a " + e + " cannot be empty.");
}
}
15 changes: 10 additions & 5 deletions src/main/java/Friend.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
public class Friend {

private String name;
private String birthday;
private int phoneNumber;
private boolean isClose;

Expand All @@ -11,21 +10,18 @@ public class Friend {
*/
public Friend(String name) {
this.name = name;
this.birthday = "01/01/2000";
this.phoneNumber = 91234567;
this.isClose = false;
}

/**
* Constructor for the class.
* @param name
* @param birthday
* @param phoneNumber
* @param isClose
*/
public Friend(String name, String birthday, int phoneNumber, boolean isClose) {
public Friend(String name, int phoneNumber, boolean isClose) {
this.name = name;
this.birthday = birthday;
this.phoneNumber = phoneNumber;
this.isClose = isClose;
}
Expand Down Expand Up @@ -61,4 +57,13 @@ public void updateRelation(boolean isClose) {
public String getName() {
return this.name;
}

/**
* Get a string of the details of the friend.
* @return a string of the friend.
*/
@Override
public String toString() {
return this.name + " (number: " + this.phoneNumber + ", isClose: " + this.isClose + ")";
}
}
12 changes: 10 additions & 2 deletions src/main/java/FriendList.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,23 @@ public FriendList(ArrayList<Friend> friends) {
* Delete the friend from your friend list.
* @param pos
*/
public void deleteFriend(int pos) {
public void delete(int pos) {
friends.remove(pos);
}

/**
* Add new friend.
* @param friend
*/
public void addFriend(Friend friend) {
public void add(Friend friend) {
friends.add(friend);
}

/**
* Get the current list of friends
* @return a list of friends.
*/
public List<Friend> getList() {
return friends;
}
}
37 changes: 37 additions & 0 deletions src/main/java/FriendListCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import java.io.IOException;

public class FriendListCommand extends Command {

/**
* Generate a list of tasks to user.
* @param friends
* @param ui
* @param storage
* @return a String to reply user.
* @throws IOException
*/
public String execute(FriendList friends, Ui ui, Storage storage) throws IOException {
return ui.generateFriendList(friends);
}

/**
* Empty execution.
* @param tasks
* @param ui
* @param storage
* @return null value as there is no tasks
* @throws IOException
*/
@Override
public String execute(TaskList tasks, Ui ui, Storage storage) throws IOException {
return null;
}

/**
* To check if the command is an exit command
* @return a false
*/
public boolean isExit() {
return false;
}
}
6 changes: 3 additions & 3 deletions src/main/java/IncorrectInputException.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
public class IncorrectInputException extends Exception {
public class IncorrectInputException extends Throwable {

public IncorrectInputException(String e) {
super(e);
public IncorrectInputException(String s) {
super(s);
}
}

0 comments on commit b468f91

Please sign in to comment.