forked from nus-cs2113-AY2021S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
58 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/main/java/diet/dietmanager/command/DietSessionDelete.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package diet.dietmanager.command; | ||
|
||
import diet.dietsession.Food; | ||
import storage.diet.Storage; | ||
|
||
import java.io.File; | ||
|
||
public class DietSessionDelete implements Command { | ||
static final String FILEPATH = "saves/diet/"; | ||
|
||
@Override | ||
public void execute(String input, Storage storage) { | ||
File folder = new File(FILEPATH); | ||
File[] listOfFiles = folder.listFiles(); | ||
try { | ||
assert !input.isEmpty(); | ||
int index = Integer.parseInt(input); | ||
assert listOfFiles != null; | ||
String fileName = listOfFiles[Integer.parseInt(input) - 1].getName(); | ||
System.out.println("Oh no! You have deleted " + fileName); | ||
listOfFiles[Integer.parseInt(input) - 1].delete(); | ||
} catch (IndexOutOfBoundsException | NumberFormatException e) { | ||
System.out.println("Sorry! It seems like you've entered an invalid number or input!"); | ||
} | ||
} | ||
} |