Skip to content

Commit

Permalink
Merge branch 'branch-level-7'
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/java/controller/TaskManager.java
  • Loading branch information
XunyiiZ committed Feb 18, 2022
2 parents 1fb33c4 + 79d39e9 commit 865e4c7
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 4 deletions.
1 change: 1 addition & 0 deletions data/task-file
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
T | | read
2 changes: 0 additions & 2 deletions src/main/java/IllegalShapeException.java

This file was deleted.

156 changes: 154 additions & 2 deletions src/main/java/controller/TaskManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,29 @@
import task.Task;
import task.Todo;


import java.util.ArrayList;
import java.util.Scanner;
import java.util.List;
import java.io.IOException;
import java.io.FileWriter;


public class TaskManager {
private static final String INDENT = " ";
private static final String LINE="-------------------------------------------";
public static final String SPACE = " ";
private static final int MAX_TASK_COUNT = 100;
private static final String DIR = "data/task-file";
private static final String FILE_SEPARATOR = " | ";


private static int taskCount=0;
private static ArrayList<Task> taskList = new ArrayList<>();
private static Scanner sc = new Scanner(System.in);


public static void main(String[] args) {
public static void main(String[] args) {
greet();
String input = getInput();
String action = getAction(input);
Expand Down Expand Up @@ -68,6 +75,7 @@ private static void updateTaskCount(){
}

private static void bye() {
save(DIR, taskList);
System.out.println(INDENT + "Bye. Hope to see you again soon!");
printLine();
}
Expand Down Expand Up @@ -164,8 +172,152 @@ private static void addTaskByMessage(String action, String input){
}
addTask(newTask);
}


// private static void retrieveData() {
// File f = new File(DIR);
// if(f.exists()){
// taskList = load(f);
// }else{
// f.getParentFile().mkdir();
// f.createNewFile();
// taskList = new ArrayList<Task>();
// save(DIR, taskList);
// }
// }

private static void save(String filename, ArrayList<Task> al){
StringBuilder sb = new StringBuilder();
List newList = new ArrayList();
for(int i = 0; i < al.size(); i++){
Task task = al.get(i);
if(task == null) break;
String taskType = task.getTypeIcon();
String taskStatus = task.getStatusIcon();
String taskDetails = task.getDescription();
sb.append(taskType);
sb.append(FILE_SEPARATOR);
sb.append(taskStatus);
sb.append(FILE_SEPARATOR);
sb.append(taskDetails);
if(taskType.equals("D") || taskType.equals("E")){
sb.append(FILE_SEPARATOR);
sb.append(task.getTime());
}
sb.append(System.lineSeparator());
}
try {
writeToFile(filename, sb.toString());
} catch (IOException e) {
System.out.println("Something went wrong:" + e.getMessage());
}
}

public static void writeToFile(String fileName, String data) throws IOException {
FileWriter fw = new FileWriter(fileName);
fw.write(data);
fw.close();
}


//
// public static List read(String filename) throws IOException{
// File f = new File(filename);
// Scanner s = new Scanner(f);
// while(s.hasNext()) {
// String newLine = s.nextLine();
// Task newTask;
// StringTokenizer st = new StringTokenizer(newLine, FILE_SEPARATOR);
//
// String taskType = st.nextToken();
// String taskStatus = st.nextToken();
// String description = st.nextToken();
// if(taskType.equals("D")) {
// String time = st.nextToken();
// newTask = new Deadline(description,time);
// newTask.
// }
//
//
//
// }
// try{
// List data = new ArrayList();
// Scanner scanner = new Scanner(new FileInputStream(filename));
// try {
// while (scanner.hasNextLine()) {
// data.add(scanner.nextLine());
// }
// } finally {
// scanner.close();
// }
// return data;
// }catch(IOException e){
// System.out.println("reading file unsuccessfully");
// e.printStackTrace();
// return null;
// }
// }




// try {
// File file = new File(dir);
// if (file.exists()) {
// orders = load(dir);
// } else {
// file.getParentFile().mkdir();
// file.createNewFile();
// orders = new ArrayList<Order>();
// save(dir, orders);
// }
// } catch (IOException e) {
// e.printStackTrace();
// }
}


//
// /**
// * This method is to load orders from external files
// * @param filename
// * specifies where the external files stored
// * @return all reservations read from the file
// */
// @Override
// public ArrayList load(String filename) {
// ArrayList stringArray = (ArrayList) read(filename);
// ArrayList alr = new ArrayList();
//
// for (int i = 0; i < stringArray.size(); i++) {
// String st = (String) stringArray.get(i);
// StringTokenizer star = new StringTokenizer(st, "|");
//
// int orderId = Integer.parseInt(star.nextToken().trim());
// int staffId = Integer.parseInt(star.nextToken().trim());
// int tableId = Integer.parseInt(star.nextToken().trim());
// int numberOfPax = Integer.parseInt(star.nextToken().trim());
// int orderSize = Integer.parseInt(star.nextToken().trim()); // write the orderSize in the file in order to read different size of order items
// boolean isActive = Boolean.parseBoolean(star.nextToken().trim());
//
// //create order with no order item
// Order order = new Order(orderId, staffId, tableId, numberOfPax, isActive);
// //add order item in order
// for (int j = 0; j < orderSize; j++) {
// int itemId = Integer.parseInt(star.nextToken().trim());
// String name = star.nextToken().trim();
// int quantity = Integer.parseInt(star.nextToken().trim());
// double price = Double.parseDouble(star.nextToken().trim());
// order.addOrderItem(itemId, quantity, name, price);
// }
// //add order to order list
// alr.add(order);
// }
// return alr;
//
// }


//
//public class Cup<T>{
// private T item;
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/task/Deadline.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,10 @@ public String toString(){
return "[D]" + super.toString() + "(by: " + by + ")";
}

public String getTypeIcon(){return "D";}

public String getTime(){
return by;
}

}
4 changes: 4 additions & 0 deletions src/main/java/task/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ public Event(String description, String at) {
public String toString(){
return "[E]" + super.toString() + "(at: " + at + ")";
}
public String getTypeIcon(){return "E";}
public String getTime(){
return at;
}



Expand Down
9 changes: 9 additions & 0 deletions src/main/java/task/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ public String getStatusIcon(){
return (isDone ? "X" : " ");
}

public String getDescription() {
return description;
}

public void markAsDone(){
this.isDone=true;
}
Expand All @@ -25,4 +29,9 @@ public String toString(){
return "[" + getStatusIcon() + "] " + description;
}

public String getTypeIcon(){return null;}

public String getTime(){return null;}


}
3 changes: 3 additions & 0 deletions src/main/java/task/Todo.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ public Todo(String description){
public String toString(){
return "[T]"+super.toString();
}

public String getTypeIcon(){return "T";}

}

0 comments on commit 865e4c7

Please sign in to comment.