1212import java .util .Scanner ;
1313
1414public class FileIO {
15+
16+ public static final int INDEX_OF_TASK_TYPE = 1 ;
17+
1518 public static void readFromFile () {
16- if (! doesFileExist ()) {
19+ if (doesFileNotExist ()) {
1720 return ;
1821 }
1922 File data = new File ("data/data.txt" );
@@ -27,7 +30,7 @@ public static void readFromFile() {
2730 }
2831 }
2932
30- private static boolean doesFileExist () {
33+ private static boolean doesFileNotExist () {
3134 File folder = new File ("data" );
3235 if (!folder .exists ()) {
3336 System .out .println ("\u2639 OOPS!!! Folder does not exist. Creating a folder named \" data\" in the same directory..." );
@@ -36,7 +39,7 @@ private static boolean doesFileExist() {
3639 System .out .println ("Folder is created successfully." );
3740 } else {
3841 System .out .println ("Please create a folder named \" data\" in the same directory manually." );
39- return false ;
42+ return true ;
4043 }
4144 }
4245 File data = new File ("data/data.txt" );
@@ -50,22 +53,22 @@ private static boolean doesFileExist() {
5053 System .out .println ("Please create a text file named \" data\" in the \" data\" folder manually." );
5154 }
5255 } catch (IOException e ) {
53- return false ;
56+ return true ;
5457 }
5558 }
56- return true ;
59+ return false ;
5760 }
5861
5962 public static void writeToFile (TaskList taskList ) {
60- if (! doesFileExist ()) {
63+ if (doesFileNotExist ()) {
6164 return ;
6265 }
6366 File data = new File ("data/data.txt" );
6467 try {
6568 FileWriter fw = new FileWriter (data .getAbsolutePath ());
6669 ArrayList <Task > list = taskList .getList ();
6770 for (int i = 0 ; i < taskList .getNumberOfTasks (); i ++) {
68- String input = handleStatusAndDescription (list , i );
71+ String input = formatListDataIntoStorageForm (list , i );
6972 fw .write (input + "\n " );
7073 }
7174 fw .close ();
@@ -74,18 +77,18 @@ public static void writeToFile(TaskList taskList) {
7477 }
7578 }
7679
77- private static String handleStatusAndDescription (ArrayList <Task > list , int index ) {
80+ private static String formatListDataIntoStorageForm (ArrayList <Task > list , int index ) {
7881 String output ;
7982 String input = list .get (index ).getStatusAndDescription ();
80- switch (input .strip ().toCharArray ()[1 ]) {
83+ switch (input .strip ().toCharArray ()[INDEX_OF_TASK_TYPE ]) {
8184 case ('T' ):
8285 output = "todo " + list .get (index ).getDescription ();
8386 break ;
8487 case ('D' ):
85- output = "deadline " + list .get (index ).getDescription () + "/by " + list .get (index ).getAdditionalInfomation ();
88+ output = "deadline " + list .get (index ).getDescription () + "/by " + list .get (index ).getAdditionalInformation ();
8689 break ;
8790 case ('E' ):
88- output = "event " + list .get (index ).getDescription () + "/at " + list .get (index ).getAdditionalInfomation ();
91+ output = "event " + list .get (index ).getDescription () + "/at " + list .get (index ).getAdditionalInformation ();
8992 break ;
9093 default :
9194 return null ;
0 commit comments