Advertisement
Guest User

bitches

a guest
May 6th, 2015
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.16 KB | None | 0 0
  1. if (args.length != 0 && args[0].equals("test")) {
  2.             Scanner sc = new Scanner("fileName");
  3.             while (sc.hasNext()) { 
  4.                 switch (sc.next()) {
  5.                 case "save":
  6.                     //FORMAT: "save"
  7.                     if (tl.save("../save.txt")) {
  8.                         System.out.println("Saved file successfully.");
  9.                     } else {
  10.                         System.out.println("File could not be saved.");
  11.                     }
  12.                    
  13.                     break;
  14.                 case "import":
  15.                     //FORMAT: "import [filePath]
  16.                     String importPath = sc.next();
  17.                    
  18.                     if (importPath.length() == 0) {
  19.                         System.out.println("Please make sure the filepath is not empty.");
  20.                         break;
  21.                     } else {
  22.                         if (tl.importFile(importPath)) {
  23.                             break;
  24.                         } else {
  25.                             System.out.println("Could not find file. Please try again.");
  26.                             break;
  27.                         }
  28.                     }
  29.                 case "export":
  30.                     //FORMAT: "export [filePath]"
  31.                     String exportPath = sc.next();
  32.                    
  33.                     if (exportPath.length() == 0) {
  34.                         System.out.println("Please make sure the filepath is not empty.");
  35.                         break;
  36.                     } else {
  37.                         if (tl.save(exportPath)) {
  38.                             break;
  39.                         } else {
  40.                             System.out.println("Could not find file. Please try again.");
  41.                             break;
  42.                         }
  43.                     }
  44.                 case "exit":
  45.                     //FORMAT: "exit"
  46.                     System.out.println("Exiting Program.");
  47.                     System.exit(0);
  48.                     break;
  49.                 case "addtask":
  50.                     //FORMAT: "addtask [groupName] [taskName] [priority] [description] [2016/04/14] [2016/04/15]"
  51.                     if (tl.groups.size() != 0) {
  52.                         String groupName = sc.next();
  53.                         for (int i = 0; i < tl.groups.size(); i++) {
  54.                             if (tl.groups.get(i).getName().equals(groupName)) {
  55.                                 // create new task if possible with given input
  56.                                 try {
  57.                                     DateFormat format = new SimpleDateFormat("yyyy/MM/dd");
  58.                                     String name = sc.next();
  59.                                     int priority = sc.nextInt();
  60.                                     String desc = sc.next();
  61.                                     Date date = format.parse(sc.next());
  62.                                     Date alarm = format.parse(sc.next());
  63.                                    
  64.                                     // check if any of the fields were left blank
  65.                                     if (name.equals("") || desc.equals("") || date.equals("") || alarm.equals("")) {
  66.                                         System.out.println("Please make sure all fields are filled out.");
  67.                                         break;
  68.                                     }
  69.            
  70.                                     Task newTask = new Task(name, priority, desc, date, alarm);
  71.                                     tl.groups.get(i).addTask(newTask);
  72.            
  73.                                     // sort the group that the new task was added to
  74.                                     // according to current sort
  75.                                     tl.sortTasks(tl.groups.get(i).tasks, tl.currentTaskSort);
  76.            
  77.                                     // TESTING
  78.                                     System.out.println("Created task: " + name + " in group: " + tl.groups.get(i).getName());
  79.                                     break;
  80.                                 } catch (ParseException e) {
  81.                                     System.out.println("Invalid date format. Please try again.");
  82.                                     break;
  83.                                 }
  84.                             }
  85.                         }
  86.                     } else {
  87.                         System.out.println("Please create a group first.");
  88.                         break;
  89.                     }
  90.                     break;
  91.                 case "addgroup":
  92.                     //FORMAT: "addgroup [groupName] [priority] [description]"
  93.                     Group newGroup = null;
  94.                     boolean groupExists = false;
  95.                    
  96.                     String name = sc.next();
  97.                     int priority = sc.nextInt();
  98.                     String desc = sc.next();
  99.  
  100.                     // check if any of the fields were left blank
  101.                     if (name.equals("") || desc.equals("")) {
  102.                         System.out.println("Please make sure all fields are filled out.");
  103.                         break;
  104.                     }
  105.  
  106.                     // check whether or not a group with the same name already
  107.                     // exists
  108.                     for (int i = 0; i < tl.groups.size(); i++) {
  109.                         if (tl.groups.get(i).getName().equals(name)) {
  110.                             groupExists = true;
  111.                             System.out.println("Group already exists.");
  112.                             break;
  113.                         }
  114.                     }
  115.  
  116.                     // if the group does not exist, add it to the groups array
  117.                     if (!groupExists) {
  118.                         newGroup = new Group(name, priority, desc);
  119.                         tl.groups.add(newGroup);
  120.  
  121.                         // re-sort groups according to current group sort
  122.                         tl.sortGroups(tl.currentGroupSort);
  123.  
  124.                         // TESTING
  125.                         System.out.println("Group: " + newGroup.getName() + " created successfully.");
  126.                     }
  127.                     break;
  128.                 case "sorttasks":
  129.                     //FORMAT: "sorttasks [0-alphabetical / 1-priority / 2-due date]"
  130.                     int sortType = sc.nextInt();
  131.                    
  132.                     switch (sortType) {
  133.                     case 0:
  134.                         for (int i = 0 ; i < tl.groups.size() ; i++)
  135.                             tl.sortTasks(tl.groups.get(i).tasks, 0);
  136.                         System.out.println("Tasks sorted in alphabetical order.");
  137.                         break;
  138.                     case 1:
  139.                         for (int i = 0 ; i < tl.groups.size() ; i++)
  140.                             tl.sortTasks(tl.groups.get(i).tasks, 1);
  141.                         System.out.println("Tasks sorted by priority.");
  142.                         break;
  143.                     case 3:
  144.                         for (int i = 0 ; i < tl.groups.size() ; i++)
  145.                             tl.sortTasks(tl.groups.get(i).tasks, 0);
  146.                         System.out.println("Tasks sorted by due date.");                       
  147.                         break;
  148.                     }
  149.                    
  150.                     break;
  151.                 case "sortgroups":
  152.                     //FORMAT: "sortgroups [0-alphabetical / 1-priority]"
  153.                     int sortType2 = sc.nextInt();
  154.                    
  155.                     switch (sortType2) {
  156.                     case 0:
  157.                         tl.sortGroups(0);
  158.                         System.out.println("Groups sorted in alphabetical order.");
  159.                         break;
  160.                     case 1:
  161.                         tl.sortGroups(1);
  162.                         System.out.println("Groups sorted by priority.");
  163.                         break;
  164.                     }
  165.                     break;                 
  166.                
  167.                 }
  168.             }
  169.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement