Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (args.length != 0 && args[0].equals("test")) {
- Scanner sc = new Scanner("fileName");
- while (sc.hasNext()) {
- switch (sc.next()) {
- case "save":
- //FORMAT: "save"
- if (tl.save("../save.txt")) {
- System.out.println("Saved file successfully.");
- } else {
- System.out.println("File could not be saved.");
- }
- break;
- case "import":
- //FORMAT: "import [filePath]
- String importPath = sc.next();
- if (importPath.length() == 0) {
- System.out.println("Please make sure the filepath is not empty.");
- break;
- } else {
- if (tl.importFile(importPath)) {
- break;
- } else {
- System.out.println("Could not find file. Please try again.");
- break;
- }
- }
- case "export":
- //FORMAT: "export [filePath]"
- String exportPath = sc.next();
- if (exportPath.length() == 0) {
- System.out.println("Please make sure the filepath is not empty.");
- break;
- } else {
- if (tl.save(exportPath)) {
- break;
- } else {
- System.out.println("Could not find file. Please try again.");
- break;
- }
- }
- case "exit":
- //FORMAT: "exit"
- System.out.println("Exiting Program.");
- System.exit(0);
- break;
- case "addtask":
- //FORMAT: "addtask [groupName] [taskName] [priority] [description] [2016/04/14] [2016/04/15]"
- if (tl.groups.size() != 0) {
- String groupName = sc.next();
- for (int i = 0; i < tl.groups.size(); i++) {
- if (tl.groups.get(i).getName().equals(groupName)) {
- // create new task if possible with given input
- try {
- DateFormat format = new SimpleDateFormat("yyyy/MM/dd");
- String name = sc.next();
- int priority = sc.nextInt();
- String desc = sc.next();
- Date date = format.parse(sc.next());
- Date alarm = format.parse(sc.next());
- // check if any of the fields were left blank
- if (name.equals("") || desc.equals("") || date.equals("") || alarm.equals("")) {
- System.out.println("Please make sure all fields are filled out.");
- break;
- }
- Task newTask = new Task(name, priority, desc, date, alarm);
- tl.groups.get(i).addTask(newTask);
- // sort the group that the new task was added to
- // according to current sort
- tl.sortTasks(tl.groups.get(i).tasks, tl.currentTaskSort);
- // TESTING
- System.out.println("Created task: " + name + " in group: " + tl.groups.get(i).getName());
- break;
- } catch (ParseException e) {
- System.out.println("Invalid date format. Please try again.");
- break;
- }
- }
- }
- } else {
- System.out.println("Please create a group first.");
- break;
- }
- break;
- case "addgroup":
- //FORMAT: "addgroup [groupName] [priority] [description]"
- Group newGroup = null;
- boolean groupExists = false;
- String name = sc.next();
- int priority = sc.nextInt();
- String desc = sc.next();
- // check if any of the fields were left blank
- if (name.equals("") || desc.equals("")) {
- System.out.println("Please make sure all fields are filled out.");
- break;
- }
- // check whether or not a group with the same name already
- // exists
- for (int i = 0; i < tl.groups.size(); i++) {
- if (tl.groups.get(i).getName().equals(name)) {
- groupExists = true;
- System.out.println("Group already exists.");
- break;
- }
- }
- // if the group does not exist, add it to the groups array
- if (!groupExists) {
- newGroup = new Group(name, priority, desc);
- tl.groups.add(newGroup);
- // re-sort groups according to current group sort
- tl.sortGroups(tl.currentGroupSort);
- // TESTING
- System.out.println("Group: " + newGroup.getName() + " created successfully.");
- }
- break;
- case "sorttasks":
- //FORMAT: "sorttasks [0-alphabetical / 1-priority / 2-due date]"
- int sortType = sc.nextInt();
- switch (sortType) {
- case 0:
- for (int i = 0 ; i < tl.groups.size() ; i++)
- tl.sortTasks(tl.groups.get(i).tasks, 0);
- System.out.println("Tasks sorted in alphabetical order.");
- break;
- case 1:
- for (int i = 0 ; i < tl.groups.size() ; i++)
- tl.sortTasks(tl.groups.get(i).tasks, 1);
- System.out.println("Tasks sorted by priority.");
- break;
- case 3:
- for (int i = 0 ; i < tl.groups.size() ; i++)
- tl.sortTasks(tl.groups.get(i).tasks, 0);
- System.out.println("Tasks sorted by due date.");
- break;
- }
- break;
- case "sortgroups":
- //FORMAT: "sortgroups [0-alphabetical / 1-priority]"
- int sortType2 = sc.nextInt();
- switch (sortType2) {
- case 0:
- tl.sortGroups(0);
- System.out.println("Groups sorted in alphabetical order.");
- break;
- case 1:
- tl.sortGroups(1);
- System.out.println("Groups sorted by priority.");
- break;
- }
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement