コード例 #1
0
 public void init() {
   Scanner scan = new Scanner(System.in);
   count = scan.nextInt();
   x0 = scan.nextLong();
   y0 = scan.nextLong();
   int result = 0;
   boolean special = false;
   for (int i = 0; i < count; i++) {
     long tempx = scan.nextLong();
     long tempy = scan.nextLong();
     if (tempx == x0 && tempy == y0) {
       special = true;
       continue;
     }
     boolean isDuplicate = false;
     for (int j = 0; j < result; j++) {
       long x1 = xList.get(j);
       long y1 = yList.get(j);
       if ((x1 - x0) * (tempy - y0) == (y1 - y0) * (tempx - x0)) {
         isDuplicate = true;
         break;
       }
     }
     if (!isDuplicate) {
       xList.add(tempx);
       yList.add(tempy);
       result++;
     }
   }
   if (special && result == 0) result = 1;
   System.out.println(result);
   scan.close();
 }
コード例 #2
0
  public static void main(String[] args) {
    // TODO Auto-generated method stub
    Scanner in = new Scanner(System.in);
    int t = in.nextInt();
    TreeMap<Long, Long> tmap = new TreeMap<>();
    long res = 0;
    while (t-- > 0) {
      res = 0;
      int n = in.nextInt();
      long m = in.nextLong();
      tmap.clear();
      long[] arr = new long[n];
      res = in.nextLong();
      arr[0] = res % m;
      res = Long.MIN_VALUE;
      tmap.put(arr[0], arr[0]);
      for (int i = 1; i < arr.length; i++) {
        arr[i] = in.nextLong();
        arr[i] %= m;
        arr[i] += arr[i - 1];
        arr[i] %= m;

        if (tmap.higherEntry(arr[i]) == null) {
          res = Math.max(res, arr[i]);
          tmap.put(arr[i], arr[i]);
          continue;
        }
        long val = tmap.higherEntry(arr[i]).getValue();
        res = Math.max(res, (arr[i] - val + m) % m);
        tmap.put(arr[i], arr[i]);
      }

      System.out.println(res);
    }
  }
コード例 #3
0
 public static void main(String args[]) {
   Scanner scan = new Scanner(System.in);
   long T = scan.nextLong();
   for (long i = 0; i < T; i++) {
     long N = scan.nextLong() - 1;
     long sum = ap(N / 3, 3, 3) + ap(N / 5, 5, 5) - ap(N / 15, 15, 15);
     System.out.println(sum);
   }
 }
コード例 #4
0
 public static void main(String[] args) {
   /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
   Scanner scan = new Scanner(System.in);
   long T = scan.nextLong();
   for (long i = 0; i < T; i++) {
     long N = scan.nextLong();
     long diff = 0;
     diff = wholeSum(N) - indiSum(N);
     System.out.println(diff);
   }
 }
コード例 #5
0
  private static boolean getNumberOfLines(File file, int total, float mean) {

    try {
      double difSum = 0;
      long last, actual;
      int nLines = 0;

      Scanner scan = new Scanner(file);
      scan.useLocale(Locale.US);

      if (scan.hasNextLine()) {
        scan.nextLine();
        if (scan.hasNextLong() && scan.hasNextLine()) {
          last = scan.nextLong();
          nLines++;
          scan.nextLine();
        } else {
          scan.close();
          return false;
        }
      } else {
        scan.close();
        return false;
      }

      while (scan.hasNextLong()) {
        actual = scan.nextLong();
        nLines++;
        difSum += actual - last;
        last = actual;

        if (scan.hasNextLine()) {
          scan.nextLine();
        } else {
          break;
        }
      }

      scan.close();

      total = nLines;
      mean = (float) difSum / (total - 1);

      return true;
    } catch (FileNotFoundException e1) {
      return false;
    }
  }
コード例 #6
0
ファイル: SJF.java プロジェクト: shreeshaprabhu/os-assignment
  public static void main(String[] args) throws IOException {
    Scanner scr = new Scanner(System.in);

    System.out.print("Enter the number of jobs: ");
    int n = scr.nextInt();

    Set<Job> jobs = new HashSet<>();
    System.out.println("Enter the arrival time and burst time of each job");
    for (int i = 1; i <= n; i++) jobs.add(new Job(i, scr.nextLong(), scr.nextLong(), 1));

    JobSchedule sjf = new SJF(jobs);
    System.out.println("Average Turn Around Time: " + sjf.averageTurnAroundTime());
    System.out.println("Average Waiting Time: " + sjf.averageWaitingTime());

    scr.close();
  }
コード例 #7
0
ファイル: p2010.java プロジェクト: nazarov-yuriy/contests
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    PrintWriter out = new PrintWriter(System.out);

    long n = in.nextLong();
    long x = in.nextLong() - 1;
    long y = in.nextLong() - 1;
    long nx = n - x;
    long ny = n - y;

    long king = 0;
    if (x - 1 >= 0 && y - 1 >= 0) king++;
    if (x - 1 >= 0 && y + 0 < n) king++;
    if (x - 1 >= 0 && y + 1 < n) king++;
    if (x + 0 < n && y - 1 >= 0) king++;
    if (x + 0 < n && y + 1 < n) king++;
    if (x + 1 < n && y - 1 >= 0) king++;
    if (x + 1 < n && y + 0 < n) king++;
    if (x + 1 < n && y + 1 < n) king++;

    long knight = 0;
    if (x + 1 < n && y + 2 < n) knight++;
    if (x + 2 < n && y + 1 < n) knight++;
    if (x - 1 >= 0 && y - 2 >= 0) knight++;
    if (x - 2 >= 0 && y - 1 >= 0) knight++;
    if (x + 1 < n && y - 2 >= 0) knight++;
    if (x + 2 < n && y - 1 >= 0) knight++;
    if (x - 1 >= 0 && y + 2 < n) knight++;
    if (x - 2 >= 0 && y + 1 < n) knight++;

    long bishop = 2 * n - 2 - Math.abs(x - y) - Math.abs(n - 1 - x - y);
    long rook = 2 * n - 2;
    long queen = rook + bishop;

    out.print("King: ");
    out.println(king);
    out.print("Knight: ");
    out.println(knight);
    out.print("Bishop: ");
    out.println(bishop);
    out.print("Rook: ");
    out.println(rook);
    out.print("Queen: ");
    out.println(queen);

    out.flush();
  }
コード例 #8
0
ファイル: Charlie.java プロジェクト: cohadar/gcj-practice
 public static Charlie load(Scanner scanner) {
   int na = scanner.nextInt();
   int nb = scanner.nextInt();
   assert 1 <= na && na <= 100 : "out of range, na: " + na;
   assert 1 <= nb && nb <= 100 : "out of range, nb: " + nb;
   long[] CA = new long[na];
   int[] TA = new int[na];
   long[] CB = new long[nb];
   int[] TB = new int[nb];
   for (int i = 0; i < na; i++) {
     CA[i] = scanner.nextLong();
     TA[i] = scanner.nextInt() - 1;
   }
   for (int i = 0; i < nb; i++) {
     CB[i] = scanner.nextLong();
     TB[i] = scanner.nextInt() - 1;
   }
   return new Charlie(CA, TA, CB, TB);
 }
コード例 #9
0
ファイル: encryptOut.java プロジェクト: mo0o/Sociograph
  public static LinkedList<profile> importer() throws IOException {

    LinkedList<profile> people = new LinkedList<profile>();
    Scanner sFile;
    profile entry;

    try {
      sFile =
          new Scanner(new File("/Users/richarddavies/NetBeansProjects/typ_MatlabGraph/users.dat"));
      sFile.nextLine();
      while (sFile.hasNext()) {

        String profile = sFile.nextLine();
        // System.out.println(profile);

        Scanner profScan = new Scanner(profile);
        profScan.useDelimiter(",");

        while (profScan.hasNext()) {

          Long id = profScan.nextLong();
          String ident = String.valueOf(id);
          String rot_Id = rot13.encrypt(ident);
          Long rot_IntId = Long.parseLong(rot_Id);

          String fname = profScan.next();
          String rot_Name = rot13.encrypt(fname);
          // String sname = profScan.next();
          // int age = profScan.nextInt();
          String gender = profScan.next();
          String nat = profScan.next();

          entry = new profile(id, fname, gender, nat);
          // System.out.println("id: "+id+" name: "+fname+" gender: "+gender+" nationality: "+nat);
          // System.out.println("id: "+rot_IntId+" name: "+rot_Name+" gender: "+gender+"
          // nationality: "+nat);
          people.add(entry);
        }
      }

    } catch (IOException ex) {
      // return people;

      System.out.println("(No System File profile.txt)" + ex);
    }
    return people;
  }
コード例 #10
0
  public static void main(String[] argh) {
    Scanner sc = new Scanner(System.in);
    int t = sc.nextInt();

    for (int i = 0; i < t; i++) {
      try {
        long x = sc.nextLong();
        System.out.println(x + " can be fitted in:");
        if (x >= -128 && x <= 127) System.out.println("* byte");
        if (x >= -Math.pow(2, 15) && x <= (Math.pow(2, 15) - 1)) System.out.println("* short");
        if (x >= -Math.pow(2, 31) && x <= (Math.pow(2, 31) - 1)) System.out.println("* int");
        if (x >= -Math.pow(2, 63) && x <= (Math.pow(2, 63) - 1)) System.out.println("* long");
      } catch (Exception e) {
        System.out.println(sc.next() + " can't be fitted anywhere.");
      }
    }
  }
コード例 #11
0
ファイル: A.java プロジェクト: jmankhan/ACM
  public void solve() throws Exception {
    long a = in.nextLong();
    long b = in.nextLong();

    long ans = 0;
    while (a != 0 && b != 0) {
      if (a > b) {
        ans += a / b;
        a = a % b;
      } else {
        ans += b / a;
        b = b % a;
      }
    }

    out.println(ans);
  }
コード例 #12
0
 public void loadData(String file) {
   try {
     Scanner txt = new Scanner(new File(file));
     mp3File = txt.nextLine();
     artist = txt.nextLine();
     album = txt.nextLine();
     while (txt.hasNext()) {
       long noteTime = txt.nextLong();
       int lengthThrowaway = txt.nextInt();
       String states = txt.next().trim();
       lines.add(new Line(noteTime, states));
     }
     song = new Music(mp3File);
     song.load();
   } catch (Exception e) {
     System.out.println(e);
   }
 } // end loadData
コード例 #13
0
ファイル: B.java プロジェクト: t8m8/AtCoder
 static void solve() {
   long n = in.nextLong();
   long m = in.nextLong();
   long p = in.nextLong();
   out.println(modPow(n, p, m));
 }
コード例 #14
0
  public static void contactBookOperations(String contactBookName)
      throws IOException, ParseException {
    FileWriter fr = new FileWriter(contactBookName, true);
    BufferedReader fileReader = new BufferedReader(new FileReader(contactBookName));
    BufferedWriter fileWriter = new BufferedWriter(fr);
    String address = "";
    String name = "";
    boolean validName = false;
    String dateOfBirth = "";
    boolean dateValid = false;
    String petName = "";
    int tag = 0;
    String contactType = "";
    boolean invalidTag = false;
    boolean moreEmail = false;
    String email = "";
    String emailChoice = "";
    boolean morePhone = true;
    String phoneChoice = "";
    String phoneList = "";
    String contactAdded = "";
    long phoneNum = 0;
    int choice = 0;
    ArrayList<String> nameList =
        new ArrayList<String>(); // arrayList to hold names of contacts in the file...
    Scanner sc = new Scanner(System.in);
    String searchString = "";
    Scanner stringReader = new Scanner(System.in);
    String line = "";
    String totalDetails = "";
    // System.out.println(fileReader);
    while (choice != 6) {
      System.out.println("\nTO ADD CONTACT->PRESS 1 ");
      System.out.println("TO EDIT CONTACT->PRESS 2 ");
      System.out.println("TO REMOVE CONTACT->PRESS 3 ");
      System.out.println("TO LIST CONTACTS->PRESS 4 ");
      System.out.println("TO SEARCH CONTACT->PRESS 5 ");
      System.out.println("TO GO BACK TO PREVIOUS MENU->PRESS 6 ");
      while (!sc.hasNextInt()) {
        System.out.println("\nENTER ONLY NUMBERS RANGED FROM 0 - 6");
        sc.next();
      }

      choice = sc.nextInt();
      switch (choice) {
          // ADD A NEW CONTACT........
        case 1: // add contact option.............
          // add name
          dateValid = false;
          invalidTag = true;
          moreEmail = true;
          morePhone = true;
          email = "";
          phoneList = "";
          nameList.clear();
          System.out.println("\nENTER NAME OF THE PERSON(Ex: Aditya Dey)");
          validName = false;
          fileReader = new BufferedReader(new FileReader(contactBookName));
          while (!validName) {
            name = stringReader.nextLine(); // read contact name from user
            name = name.trim();
            if (name.equals("")) {
              System.out.println(
                  "\nNAME OF THE PERSON CANNOT BE BLANK\nENTER NAME OF THE PERSON(Ex: Aditya Dey)");
              continue;
            }
            while (((line = fileReader.readLine()) != null)) // read till end of file
            {
              String s =
                  line.substring(0, line.indexOf('=')); // add each name that exists in the file
              if (!nameList.contains(s)) {
                nameList.add(s);
              }
            }
            // System.out.println(nameList);
            if (nameList.contains(name)) // if name already exists, print error message
            {
              System.out.println("\nA CONTACT NAMED " + name + " ALREADY EXISTS.");
              System.out.println("\nPLEASE ADD ANOTHER NAME(Ex: Aditya Dey)");

            } else {
              validName = true;
              nameList.add(name);
            }
          }
          // date of birth
          System.out.println(
              "\nENTER DOB OF THE PERSON IN DD/MM/YYYY FORMAT Ex: 12/05/1992 OR PRESS ENTER TO SKIP");
          while (!dateValid) {
            dateOfBirth = stringReader.nextLine();
            if (dateOfBirth.trim().compareTo("") == 0) dateValid = true;
            else // doubt? next() skips next scan...
            dateValid = isValidDate(dateOfBirth);
            if (!dateValid) {
              System.out.println(
                  "\nINVALID DATE...\nENTER DOB OF THE PERSON IN DD/MM/YYYY FORMAT Ex: 12/05/1992");
            }
          }

          //	System.out.println(dateOfBirth);
          // add contact type
          System.out.println("\nENTER PET NAME OF THE PERSON OR ENTER TO SKIP");
          petName = stringReader.nextLine();

          System.out.println("\nCHOOSE CONTACT TYPE...");
          System.out.println("\nFOR FAMILY->PRESS 1 ");
          System.out.println("FOR FRIENDS->PRESS 2 ");
          System.out.println("FOR ASSOCIATES->PRESS 3 ");
          System.out.println("FOR OTHERS->PRESS 4 ");

          while (!sc.hasNextInt()) {
            System.out.println("\nENTER ONLY NUMBERS RANGED FROM 1 - 4");
            sc.nextLine();
          }
          tag = sc.nextInt();

          while (invalidTag) {
            switch (tag) {
              case 1:
                contactType = "Family";
                invalidTag = false;
                break;
              case 2:
                contactType = "Friend";
                invalidTag = false;
                break;
              case 3:
                contactType = "Associate";
                invalidTag = false;
                break;
              case 4:
                contactType = "Others";
                invalidTag = false;
                break;
              default:
                System.out.println("\nENTER ONLY NUMBERS RANGED FROM 1-4");
                invalidTag = true;
                break;
            }
          }
          // System.out.println(contactType);
          System.out.println("\nENTER ADDRESS IN ONE LINE OR PRESS ENTER TO SKIP");
          address = stringReader.nextLine();
          // System.out.println(address);
          while (moreEmail) {
            System.out.println("\nENTER EMAIL ADDRESS OR PRESS ENTER TO SKIP");
            email = email + "," + stringReader.nextLine();
            // System.out.println(email);
            if (!(email.trim()).equals(",")) {
              System.out.println(
                  "\nTO ADD EMAIL ADRESS->PRESS 'Y' OR 'y'..TO STOP ADDING EMAIL PRESS ANY OTHER KEY");
              emailChoice = stringReader.nextLine();
              if (emailChoice.equals("y") || emailChoice.equals("Y")) {
                moreEmail = true;
              } else {
                moreEmail = false;
              }
            } else {
              moreEmail = false;
            }
          }
          email = email.substring(1, email.length());
          // System.out.println(email);

          while (morePhone) {
            System.out.println("\nENTER CONTACT NUMBER");

            while (!sc.hasNextLong()) {
              System.out.println("\nINVALID CONTACT NUMBER.\nENTER A VALID CONTACT NUMBER");
              sc.next();
            }
            phoneNum = sc.nextLong();
            phoneList = phoneList + "," + phoneNum;
            sc.nextLine(); // doubt? not included: doesnt read phonechoice.....

            System.out.println(
                "\nTO ADD MORE PHONE NUMBERS->PRESS 'Y' OR 'y' \nOTHERWISE PRESS ANY OTHER KEY");
            phoneChoice = sc.nextLine();

            if (phoneChoice.equals("y") || phoneChoice.equals("Y")) {
              morePhone = true;
            } else {
              morePhone = false;
            }
          }
          phoneList = phoneList.substring(1, phoneList.length());
          System.out.println("FOLLOWING DETAILS HAS BEEN SAVED IN THE PHONEBOOK");
          System.out.println("---------------------------------------------------");
          System.out.println(
              "["
                  + name
                  + ","
                  + petName
                  + ","
                  + contactType
                  + ","
                  + address
                  + ","
                  + dateOfBirth
                  + ","
                  + email
                  + ","
                  + phoneList
                  + "]");
          totalDetails =
              name
                  + "="
                  + dateOfBirth
                  + ":"
                  + petName
                  + ":"
                  + contactType
                  + ":"
                  + address
                  + ":"
                  + email
                  + ":"
                  + phoneList
                  + ":"
                  + new Date();
          fileWriter.write(totalDetails);
          fileWriter.newLine();
          fileWriter.flush();
          break;
          // EDITING A CONTACT
        case 2:
          String editName = "";
          String details = "";
          String line3 = "";
          String[] detailParts;
          String newDob = "";
          String newPetName = "";
          String newAddress = "";
          String newContactType = "";
          String newEmail = "";
          String newPhone = "";
          String newString = "";
          String name3 = "";
          choice = 0;
          nameList.clear();
          String[] parts;
          fileReader = new BufferedReader(new FileReader(contactBookName));
          while (((line = fileReader.readLine()) != null)) // read till end of file
          {
            String s =
                line.substring(0, line.indexOf('=')); // add each name that exists in the file
            if (!nameList.contains(s)) {
              nameList.add(s);
            }
          }
          BufferedReader editReader = new BufferedReader(new FileReader(contactBookName));
          dateValid = false;
          invalidTag = true;
          String editContact = "";
          System.out.println("\nENTER THE CONTACT TO BE EDITED");
          editName = stringReader.nextLine();
          if (!nameList.contains(editName)) {
            System.out.println("\nA CONTACT NAMED " + editName + " DOES NOT EXIST");
          } else {
            while ((line3 = editReader.readLine()) != null) {
              // System.out.println(line3);
              name3 = line3.substring(0, line3.indexOf("="));
              if (!name3.equals(editName)) {
                newString = newString + line3 + System.getProperty("line.separator");
              } else {
                editContact = line3;
              }
            }
            details = editContact.substring(editContact.indexOf("=") + 1, editContact.length());
            detailParts = details.split(":");
            newDob = detailParts[0];
            newPetName = detailParts[1];
            newContactType = detailParts[2];
            newAddress = detailParts[3];
            newEmail = detailParts[4];
            newPhone = detailParts[5];
            while (choice != 7) {
              System.out.println("\nTO EDIT DATE OF BIRTH->PRESS 1");
              System.out.println("TO EDIT PET NAME->PRESS 2 ");
              System.out.println("TO EDIT CONTACT TYPE->PRESS 3 ");
              System.out.println("TO EDIT ADDRESS->PRESS 4 ");
              System.out.println("TO ADD EMAIL->PRESS 5 ");
              System.out.println("TO ADD PHONE NUMBER->PRESS 6 ");
              System.out.println("TO GO BACK TO THE PREVIOUS MENU->PRESS 7 ");
              System.out.print("ENTER YOUR CHOICE::\t");
              while (!sc.hasNextInt()) {
                System.out.println("ENTER ONLY INTEGERS IN THE RANGE 1-7");
                sc.nextLine();
              }

              choice = sc.nextInt();
              switch (choice) {
                case 1:
                  System.out.println(
                      "\nENTER DOB OF THE PERSON IN DD/MM/YYYY FORMAT EG: 12/05/1992");
                  while (!dateValid) {
                    newDob = stringReader.nextLine(); // doubt? next() skips next scan...		
                    dateValid = isValidDate(newDob);
                    if (!dateValid) {
                      System.out.println(
                          "\nINVALID DATE...ENTER DOB OF THE PERSON IN DD/MM/YYYY FORMAT EG: 12/05/1992");
                    }
                  }
                  break;
                case 2:
                  System.out.println("\nENTER NEW PET NAME OF THE PERSON OR ENTER TO SKIP");
                  newPetName = stringReader.nextLine();
                  break;

                case 3:
                  System.out.println("\nCHOOSE CONTACT TYPE...");
                  System.out.println("\nFOR FAMILY->PRESS 1 ");
                  System.out.println("FOR FRIENDS->PRESS 2 ");
                  System.out.println("FOR ASSOCIATES->PRESS 3 ");
                  System.out.println("FOR OTHERS->PRESS 4 ");
                  while (!sc.hasNextInt()) {
                    System.out.println("\nENTER ONLY NUMBERS IN THE RANGE 1 - 3");
                    sc.nextLine();
                  }
                  tag = sc.nextInt();
                  while (invalidTag) {
                    switch (tag) {
                      case 1:
                        newContactType = "Family";
                        invalidTag = false;
                        break;

                      case 2:
                        newContactType = "Friend";
                        invalidTag = false;
                        break;

                      case 3:
                        newContactType = "Associate";
                        invalidTag = false;
                        break;

                      case 4:
                        newContactType = "Others";
                        invalidTag = false;
                        break;

                      default:
                        System.out.println("\nENTER ONLY NUMBERS RANGED FROM 1-4");
                        invalidTag = true;
                        break;
                    }
                  }
                  break;
                case 4:
                  System.out.println("\nENTER NEW ADDRESS IN ONE LINE");
                  newAddress = stringReader.nextLine();
                  break;

                case 5:
                  moreEmail = true;
                  while (moreEmail) {
                    System.out.println("\nENTER EMAIL ADDRESS OR PRESS ENTER TO SKIP");
                    newEmail = newEmail + "," + stringReader.nextLine();
                    // System.out.println(email);
                    if (!(newEmail.trim()).equals(",")) {
                      System.out.println(
                          "TO ADD EMAIL->PRESS 'Y' OR 'y'..TO STOP ADDING EMAIL PRESS ANY OTHER KEY");
                      emailChoice = stringReader.nextLine();
                      if (emailChoice.equals("y") || emailChoice.equals("Y")) {
                        moreEmail = true;
                      } else {
                        moreEmail = false;
                      }
                    } else {
                      moreEmail = false;
                    }
                  }
                  break;

                case 6:
                  morePhone = true;
                  while (morePhone) {
                    System.out.println("\nENTER PHONE NUMBER");
                    while (!sc.hasNextLong()) {
                      System.out.println("\nONLY VALID PHONE NUMBERS ALLOWED");
                      sc.next();
                    }
                    phoneNum = sc.nextLong();
                    newPhone = phoneNum + ",";
                    sc.nextLine(); // doubt? not included: doesnt read phonechoice.....
                    System.out.println(
                        "\nTO ADD MORE PHONE NUMBERS->PRESS 'y' or 'Y'\nOTHERWISE PRESS ANY OTHER KEY");
                    phoneChoice = sc.nextLine();
                    if (phoneChoice.equals("y") || phoneChoice.equals("Y")) {
                      morePhone = true;
                    } else {
                      morePhone = false;
                    }
                  }
                  phoneList = newPhone;
                  phoneList = phoneList.substring(1, phoneList.length());
                  break;

                case 7:
                  System.out.println(
                      "["
                          + editName
                          + ","
                          + newPetName
                          + ","
                          + newContactType
                          + ","
                          + newAddress
                          + ","
                          + newDob
                          + ","
                          + newEmail
                          + ","
                          + newPhone
                          + "]");
                  String newDetails =
                      editName
                          + "="
                          + newDob
                          + ":"
                          + newPetName
                          + ":"
                          + newContactType
                          + ":"
                          + newAddress
                          + ":"
                          + newEmail
                          + ":"
                          + newPhone
                          + ":"
                          + new Date();
                  newString = newString + newDetails + System.getProperty("line.separator");
                  BufferedWriter editWriter = new BufferedWriter(new FileWriter(contactBookName));
                  editWriter.write(newString);
                  editWriter.close();
                  break;

                default:
                  System.out.println("\nENTER ONLY NUMBERS RANGED FROM 1-7");
                  break;
              }
            }
          }
          // dob:petname:tag:address:email1,email2,email3..:ph1,ph2,...:crtdate
          break;

        case 3: // REMOVING A CONTACT
          BufferedReader removalReader = new BufferedReader(new FileReader(contactBookName));
          String name2 = "";
          String line2 = "";
          String nameRemoved = "";
          String finalString = "";
          System.out.println("\nENTER THE NAME TO BE REMOVED");
          nameRemoved = stringReader.nextLine();
          if (!nameList.contains(nameRemoved)) {
            System.out.println("\nA CONTACT WITH NAME " + nameRemoved + " DOES NOT EXIST\n");
          } else {
            while ((line2 = removalReader.readLine()) != null) {
              name2 = line2.substring(0, line2.indexOf("="));
              if (!name2.equals(nameRemoved)) {
                finalString = finalString + line2 + System.getProperty("line.separator");
              }
            }
            BufferedWriter removalWriter = new BufferedWriter(new FileWriter(contactBookName));
            removalWriter.write(finalString);
            removalWriter.close();
            System.out.println("CONTACT " + nameRemoved + " REMOVED ");
          }
          break;
          // LISTING ELEMENTS
        case 4:
          int listChoice = 0;
          BufferedReader listReader = new BufferedReader(new FileReader(contactBookName));
          parts = null;
          TreeMap<String, String> nameDetailMap = new TreeMap<String, String>();
          String line4 = "";

          while (listChoice != 4) {
            System.out.println("\nTO DISPLAY CONTACTS BY ALPHABETICAL ORDERING OF NAMES->PRESS 1 ");
            System.out.println("TO DISPLAY CONTACTS BY CREATED DATE->PRESS 2 ");
            System.out.println("TO DISPLAY CONTACTS BY TAG->PRESS 3 ");
            System.out.println("TO GO BACK TO PREVIOUS MENU->PRESS 4 ");
            System.out.print("ENTER CHOICE::\t");

            while (!sc.hasNextInt()) {
              System.out.println("ENTER ONLY INTEGERS IN THE RANGE 1-4");
              sc.next();
            }

            listChoice = sc.nextInt();

            switch (listChoice) {
                // ORDERING CONTACTS BY ALPHABETICAL ORDERING OF NAMES..............
              case 1:
                listReader = new BufferedReader(new FileReader(contactBookName));

                line4 = "";
                parts = null;
                while ((line4 = listReader.readLine()) != null) {
                  parts = line4.split("=");
                  nameDetailMap.put(parts[0], parts[1]);
                }

                Collection<String> c = nameDetailMap.keySet();
                Iterator<String> it = c.iterator();
                if (it.hasNext()) {
                  System.out.println(
                      "\nCONTACTS BELOW ARE LISTED IN ALPHABETICAL ORDERING OF NAMES");
                  System.out.println("-----------------------------------------------------------");
                } else {
                  System.out.println("NO CONTACTS AVAILABLE");
                }
                while (it.hasNext()) {
                  String s = (String) it.next();
                  System.out.println("\n\n" + s);
                  System.out.println("---------------------------------");
                  String[] contactDetail = nameDetailMap.get(s).split(":");
                  for (int i = 0; i < contactDetail.length; i++) {
                    if (contactDetail[i].trim().compareTo("") == 0) {
                      contactDetail[i] = "Unavailable";
                    }
                  }
                  System.out.println("Date of Birth::\t" + contactDetail[0]);
                  System.out.println("Pet name::\t" + contactDetail[1]);
                  System.out.println("Contact Type::\t" + contactDetail[2]);
                  System.out.println("Address::\t" + contactDetail[3]);
                  System.out.println("Email Address::\t" + contactDetail[4]);
                  System.out.println("Phone No::\t" + contactDetail[5]);
                  System.out.println("Contact added::\t" + contactDetail[6]);
                }
                break;

                // ORDERING CONTACTS BY CREATED DATE..............
              case 2:
                BufferedReader br = new BufferedReader(new FileReader(contactBookName));
                line4 = "";
                String date = "";
                String[] part;
                TreeMap<Date, String> tm = new TreeMap<Date, String>();
                while ((line4 = br.readLine()) != null) {
                  part = line4.split(":");
                  SimpleDateFormat formatter = new SimpleDateFormat("E MMM dd H:m");
                  String h = (part[6] + ":" + part[7]);
                  Date d = formatter.parse(h);
                  tm.put(d, line4);
                }
                Collection<Date> c1 = tm.keySet();
                // System.out.println(c1);
                Iterator<Date> it1 = c1.iterator();
                if (it1.hasNext()) {
                  System.out.println("\nCONTACTS BELOW ARE LISTED IN ORDER OF CREATED DATES");
                  System.out.println("--------------------------------------------------------");

                } else {
                  System.out.println("NO CONTACTS AVAILABLE");
                }
                while (it1.hasNext()) {
                  String s = it1.next().toString() + "";
                  // System.out.println(s);
                  System.out.println("\n\n" + s);
                  SimpleDateFormat formatter = new SimpleDateFormat("E MMM dd H:m");
                  Date d = formatter.parse(s);
                  System.out.println("---------------------------------");
                  String[] nameContact = tm.get(d).split("=");
                  System.out.println(nameContact[0]);
                  String[] contactDetail = nameContact[1].split(":");
                  for (int i = 0; i < contactDetail.length; i++) {
                    if (contactDetail[i].trim().compareTo("") == 0) {
                      contactDetail[i] = "Unavailable";
                    }
                  }
                  System.out.println("Date of Birth::\t" + contactDetail[0]);
                  System.out.println("Pet name::\t" + contactDetail[1]);
                  System.out.println("Contact Type::\t" + contactDetail[2]);
                  System.out.println("Address::\t" + contactDetail[3]);
                  System.out.println("Email Address::\t" + contactDetail[4]);
                  System.out.println("Phone No::\t" + contactDetail[5]);
                }
                break;

                //// ORDERING CONTACTS BY TAG..............
                // dob:petname:tag:address:email1,email2,email3..:ph1,ph2,...:crtdate
              case 3:
                ArrayList<String> familyList = new ArrayList<String>();
                ArrayList<String> friendsList = new ArrayList<String>();
                ArrayList<String> colleaguesList = new ArrayList<String>();
                ArrayList<String> othersList = new ArrayList<String>();
                line4 = "";
                parts = null;
                br = new BufferedReader(new FileReader(contactBookName));
                while ((line4 = br.readLine()) != null) {
                  parts = line4.split(":");
                  String relation = parts[2];

                  if (relation.equals("Family")) {
                    familyList.add(line4);
                  } else if (relation.equals("Friend")) {
                    friendsList.add(line4);
                  } else if (relation.equals("Associate")) {
                    colleaguesList.add(line4);
                  } else {
                    othersList.add(line4);
                  }
                }
                if (familyList.isEmpty()
                    && friendsList.isEmpty()
                    && colleaguesList.isEmpty()
                    && othersList.isEmpty()) {
                  System.out.println("NO CONTACTS AVAILABLE.");
                } else {
                  System.out.println("\nCONTACTS BELOW ARE LISTED ACCORDING TO TAGS");
                  System.out.println("--------------------------------------------------------");
                }
                if (!familyList.isEmpty()) {
                  System.out.println("\nFAMILY CONTACTS\n----------------------------");
                  for (Object s : familyList) {
                    String[] nameContact = s.toString().split("=");
                    System.out.println(nameContact[0] + "\n");
                    String[] contactDetail = nameContact[1].split(":");
                    for (int i = 0; i < contactDetail.length; i++) {
                      if (contactDetail[i].trim().compareTo("") == 0) {
                        contactDetail[i] = "Unavailable";
                      }
                    }
                    System.out.println("   Date of Birth::\t" + contactDetail[0]);
                    System.out.println("   Pet name::\t\t" + contactDetail[1]);
                    System.out.println("   Address::\t\t" + contactDetail[3]);
                    System.out.println("   Email Address::\t" + contactDetail[4]);
                    System.out.println("   Phone No::\t\t" + contactDetail[5]);
                    System.out.println("   Contact added::\t" + contactDetail[6]);
                  }
                }

                if (!friendsList.isEmpty()) {
                  System.out.println("\nFRIEND CONTACTS\n----------------------------");
                  for (Object s : friendsList) {
                    String[] nameContact = s.toString().split("=");
                    System.out.println(nameContact[0] + "\n");
                    String[] contactDetail = nameContact[1].split(":");
                    for (int i = 0; i < contactDetail.length; i++) {
                      if (contactDetail[i].trim().compareTo("") == 0) {
                        contactDetail[i] = "Unavailable";
                      }
                    }
                    System.out.println("   Date of Birth::\t" + contactDetail[0]);
                    System.out.println("   Pet name::\t\t" + contactDetail[1]);
                    System.out.println("   Address::\t\t" + contactDetail[3]);
                    System.out.println("   Email Address::\t" + contactDetail[4]);
                    System.out.println("   Phone No::\t\t" + contactDetail[5]);
                    System.out.println("   Contact added::\t" + contactDetail[6]);
                  }
                }
                if (!colleaguesList.isEmpty()) {
                  System.out.println("\nASSOCIATE CONTACTS\n----------------------------");
                  for (Object s : colleaguesList) {
                    String[] nameContact = s.toString().split("=");
                    System.out.println(nameContact[0] + "\n");
                    String[] contactDetail = nameContact[1].split(":");
                    for (int i = 0; i < contactDetail.length; i++) {
                      if (contactDetail[i].trim().compareTo("") == 0) {
                        contactDetail[i] = "Unavailable";
                      }
                    }
                    System.out.println("   Date of Birth::\t" + contactDetail[0]);
                    System.out.println("   Pet name::\t\t" + contactDetail[1]);
                    System.out.println("   Address::\t\t" + contactDetail[3]);
                    System.out.println("   Email Address::\t" + contactDetail[4]);
                    System.out.println("   Phone No::\t\t" + contactDetail[5]);
                    System.out.println("   Contact added::\t" + contactDetail[6]);
                  }
                }

                if (!othersList.isEmpty()) {
                  System.out.println("\nOTHER CONTACTS\n----------------------------");
                  for (Object s : othersList) {
                    String[] nameContact = s.toString().split("=");
                    System.out.println(nameContact[0] + "\n");
                    String[] contactDetail = nameContact[1].split(":");
                    for (int i = 0; i < contactDetail.length; i++) {
                      if (contactDetail[i].trim().compareTo("") == 0) {
                        contactDetail[i] = "Unavailable";
                      }
                    }
                    System.out.println("   Date of Birth::\t" + contactDetail[0]);
                    System.out.println("   Pet name::\t\t" + contactDetail[1]);
                    System.out.println("   Address::\t\t" + contactDetail[3]);
                    System.out.println("   Email Address::\t" + contactDetail[4]);
                    System.out.println("   Phone No::\t\t" + contactDetail[5]);
                    System.out.println("   Contact added::\t" + contactDetail[6]);
                  }
                }
                break;

              case 4:
                break;
              default:
                System.out.println("\nENTER ONLY INTEGERS IN THE RANGE 1-5");
                break;
            }
          }
          break;
          // SEARCH CONTACTS BOOK...
        case 5:
          String[] details1 = null;
          line4 = "";
          searchString = "";
          parts = null;
          String addedDetails = "";
          fileReader = new BufferedReader(new FileReader(contactBookName));
          System.out.println("ENTER THE STRING TO BE SERCHED FOR IN THE CONTACTS BOOK");
          searchString = stringReader.nextLine();
          ArrayList<String> nameMatchList = new ArrayList<String>();
          ArrayList<String> emailMatchList = new ArrayList<String>();
          ArrayList<String> tagMatchList = new ArrayList<String>();
          ArrayList<String> addressMatchList = new ArrayList<String>();
          ArrayList<String> dobMatchList = new ArrayList<String>();
          ArrayList<String> phoneMatchList = new ArrayList<String>();
          ArrayList<String> petNameMatchList = new ArrayList<String>();
          String addedString = "";
          while ((line4 = fileReader.readLine()) != null) {
            parts = line4.split("=");
            name = parts[0];
            details1 = parts[1].split(":");
            dateOfBirth = details1[0];
            petName = details1[1];
            contactType = details1[2];
            address = details1[3];
            email = details1[4];
            phoneList = details1[5];
            contactAdded = details1[6];

            addedString = "";
            // System.out.println("name = "+name+" dateOfbirth = "+dateOfBirth+" petName
            // ="+petName+" contactType ="+contactType+"address ="+address+"email
            // ="+email+"phoneList ="+phoneList);

            if (name.contains(searchString)) {
              addedString =
                  name
                      + "="
                      + dateOfBirth
                      + ":"
                      + petName
                      + ":"
                      + contactType
                      + ":"
                      + address
                      + ":"
                      + email
                      + ":"
                      + phoneList
                      + ":"
                      + contactAdded;
              nameMatchList.add(addedString);
            }

            if (dateOfBirth.contains(searchString)) {
              addedString =
                  name
                      + "="
                      + dateOfBirth
                      + ":"
                      + petName
                      + ":"
                      + contactType
                      + ":"
                      + address
                      + ":"
                      + email
                      + ":"
                      + phoneList
                      + ":"
                      + contactAdded;
              dobMatchList.add(addedString);
            }

            if (petName.contains(searchString)) {
              addedString =
                  name
                      + "="
                      + dateOfBirth
                      + ":"
                      + petName
                      + ":"
                      + contactType
                      + ":"
                      + address
                      + ":"
                      + email
                      + ":"
                      + phoneList
                      + ":"
                      + contactAdded;
              petNameMatchList.add(addedString);
            }

            if (contactType.contains(searchString)) {
              addedString =
                  name
                      + "="
                      + dateOfBirth
                      + ":"
                      + petName
                      + ":"
                      + contactType
                      + ":"
                      + address
                      + ":"
                      + email
                      + ":"
                      + phoneList
                      + ":"
                      + contactAdded;
              tagMatchList.add(addedString);
            }

            if (address.contains(searchString)) {
              addedString =
                  name
                      + "="
                      + dateOfBirth
                      + ":"
                      + petName
                      + ":"
                      + contactType
                      + ":"
                      + address
                      + ":"
                      + email
                      + ":"
                      + phoneList
                      + ":"
                      + contactAdded;
              addressMatchList.add(addedString);
            }

            if (email.contains(searchString)) {
              addedString =
                  name
                      + "="
                      + dateOfBirth
                      + ":"
                      + petName
                      + ":"
                      + contactType
                      + ":"
                      + address
                      + ":"
                      + email
                      + ":"
                      + phoneList
                      + ":"
                      + contactAdded;
              emailMatchList.add(addedString);
            }

            if (phoneList.contains(searchString)) {
              addedString =
                  name
                      + "="
                      + dateOfBirth
                      + ":"
                      + petName
                      + ":"
                      + contactType
                      + ":"
                      + address
                      + ":"
                      + email
                      + ":"
                      + phoneList
                      + ":"
                      + contactAdded;
              phoneMatchList.add(addedString);
            }
          }
          System.out.println(
              "\nTOTAL NUMBER OF MATCHES = "
                  + (nameMatchList.size()
                      + dobMatchList.size()
                      + petNameMatchList.size()
                      + tagMatchList.size()
                      + addressMatchList.size()
                      + emailMatchList.size()
                      + phoneMatchList.size()));
          if (!nameMatchList.isEmpty()) {
            System.out.println(
                "\nTOTAL " + nameMatchList.size() + " NAMES MATCH WITh " + searchString + "\n");
            System.out.println(
                "\nTHE NAMES OF THE FOLLOWING CONTACTS MATCHES WITH THE SEARCH STRING ");
            System.out.println(
                "--------------------------------------------------------------------------------\n");

            for (Object s : nameMatchList) {
              showContactByType(s, 2);
            }
          }
          if (!dobMatchList.isEmpty()) {
            System.out.println(
                "\nTOTAL " + dobMatchList.size() + " DOBS' MATCH WITH " + searchString + "\n");
            System.out.println(
                "\nTHE DOB'S OF THE FOLLOWING CONTACTS MATCHES WITH THE SEARCH STRING ");
            System.out.println(
                "--------------------------------------------------------------------------------\n");

            for (Object s : dobMatchList) {
              showContactByType(s, 2);
            }
          }
          if (!petNameMatchList.isEmpty()) {
            System.out.println(
                "\nTOTAL "
                    + petNameMatchList.size()
                    + " PET NAMES MATCH WITH  "
                    + searchString
                    + "\n");
            System.out.println(
                "\nTHE PET NAMES OF THE FOLLOWING CONTACTS MATCHES WITH THE SEARCH STRING ");
            System.out.println(
                "--------------------------------------------------------------------------------\n");

            for (Object s : petNameMatchList) {
              showContactByType(s, 2);
            }
          }
          if (!tagMatchList.isEmpty()) {
            System.out.println(
                "\nTOTAL "
                    + tagMatchList.size()
                    + " CONTACT TYPES MATCH WITH THE "
                    + searchString
                    + "\n");
            System.out.println(
                "\nTHE TAGS OF THE FOLLOWING CONTACTS MATCHES WITH THE SEARCH STRING ");
            System.out.println(
                "--------------------------------------------------------------------------------\n");

            for (Object s : tagMatchList) {
              showContactByType(s, 2);
            }
          }
          if (!addressMatchList.isEmpty()) {
            System.out.println(
                "\nTOTAL "
                    + addressMatchList.size()
                    + " ADDRESSES MATCH WITH "
                    + searchString
                    + "\n");
            System.out.println(
                "\nTHE ADDRESSES OF THE FOLLOWING CONTACTS MATCHES WITH THE SEARCH STRING ");
            System.out.println(
                "--------------------------------------------------------------------------------\n");

            for (Object s : addressMatchList) {
              showContactByType(s, 2);
            }
          }
          if (!emailMatchList.isEmpty()) {
            System.out.println(
                "\nTOTAL " + emailMatchList.size() + " EMAILS MATCH WITH " + searchString + "\n");
            System.out.println(
                "\nTHE EMAIL'S OF THE FOLLOWING CONTACTS MATCHES WITH THE SEARCH STRING ");
            System.out.println(
                "--------------------------------------------------------------------------------\n");

            for (Object s : emailMatchList) {
              showContactByType(s, 2);
            }
          }
          if (!phoneMatchList.isEmpty()) {
            System.out.println(
                "\nTOTAL "
                    + phoneMatchList.size()
                    + " CONTACT NUMBERS MATCH WITH "
                    + searchString
                    + "\n");
            System.out.println(
                "\nTHE PHONE NUMBERS OF THE FOLLOWING CONTACTS MATCHES WITH THE SEARCH STRING ");
            System.out.println(
                "--------------------------------------------------------------------------------\n");

            for (Object s : phoneMatchList) {
              showContactByType(s, 2);
            }
          }

          break;
        case 6:
          break;

        default:
          System.out.println("\nENTER ONLY NUMBERS  RANGED FROM 1-6");
          break;
      }
    }
    // fileReader.close();
    // fileWriter.close();
    // stringReader.close();
    // sc.close();
  }
コード例 #15
0
ファイル: edge.java プロジェクト: mo0o/Sociograph
  public static LinkedList<edge> importer(MatlabProxy proxy)
      throws IOException, MatlabConnectionException, MatlabInvocationException {

    Scanner sFile;
    edge entry;
    LinkedList<edge> tie = new LinkedList<edge>();
    Long k, p;

    try {
      sFile =
          new Scanner(new File("/Users/richarddavies/NetBeansProjects/typ_MatlabGraph/edges.dat"));

      System.out.println(sFile.nextLine());

      while (sFile.hasNext()) {

        String edge = sFile.nextLine();
        // System.out.println(edge);

        Scanner edgeScan = new Scanner(edge);
        edgeScan.useDelimiter(",");

        while (edgeScan.hasNext()) {

          k = edgeScan.nextLong();
          System.out.print(k + " ");

          String ident_k = String.valueOf(k);
          String rot_Id_k = rot13.encrypt(ident_k);
          Long rot_k = Long.parseLong(rot_Id_k);

          p = edgeScan.nextLong();
          System.out.print(p);

          String ident_p = String.valueOf(p);
          String rot_Id_p = rot13.encrypt(ident_p);
          Long rot_p = Long.parseLong(rot_Id_p);

          // System.out.println(rot_k+" : "+rot_p);
          entry = new edge(k, p);

          int n = search.search(k);
          int m = search.search(p);
          System.out.print(
              " : "
                  + Typ_MatlabGraph.people.get(n).idProf
                  + " "
                  + Typ_MatlabGraph.people.get(m).idProf);
          System.out.println("");
          n++;
          m++;

          proxy.eval("adjMatrix(" + n + "," + m + ") = 1");

          tie.add(entry);
        }
      }

    } catch (IOException ex) {

      System.out.println("(No System File profile.txt)" + ex);
    }

    return tie;
  }
コード例 #16
0
  public static boolean generateTrainingFile(
      String sensorDataFolder,
      String sensorDataFile,
      String sensorMarksFolder,
      String sensorMarksFile,
      String outFolder,
      String outFile,
      Context context) {
    IWindowData windowData = new WindowHalfOverlap(128);
    IFeatures myFeatures = new MyFeatures();

    Scanner scanSD = null, scanSM = null;
    File sensorData = MyUtil.getSDFile(sensorDataFolder, sensorDataFile);
    File sensorMarks = MyUtil.getSDFile(sensorMarksFolder, sensorMarksFile);

    try {
      scanSD = new Scanner(sensorData);
      scanSD.useLocale(Locale.US);
    } catch (FileNotFoundException e1) {
      return false;
    }

    try {
      scanSM = new Scanner(sensorMarks);
      scanSM.useLocale(Locale.US);
    } catch (FileNotFoundException e1) {
      scanSD.close();
      return false;
    }

    // progress bar
    int total = getNumberOfLines(sensorData);

    /*
       int total = 0;
       float mean = 0;
       boolean correct = getNumberOfLines(sensorData, total, mean);
       if(!correct){
       	scanSM.close();
       	scanSD.close();
       	return false;
       }

       Intent intent = new Intent("com.example.activityregistrator.UPDATE_HZ");
    intent.putExtra("hz", 1/mean);
    context.sendBroadcast(intent);
    */
    float done = 0;

    Long prevTimeSM, postTimeSM, timeSD = -1l, lastTimeSD = 0l, firstTimeSD = -1l;
    int prevLabel, postLabel;

    if (scanSM.hasNextLine()) {
      scanSM.nextLine();
      prevTimeSM = scanSM.nextLong();
      prevLabel = scanSM.nextInt();

      scanSD.nextLine();
      Intent intent = new Intent("com.example.activityregistrator.UPDATE_PROGRESS");
      intent.putExtra("progress", (float) ((++done) / total) * 100);
      context.sendBroadcast(intent);

      // find next time and label
      while (scanSM.hasNextLine()) {
        scanSM.nextLine();
        if (!scanSM.hasNextLong()) break;

        Log.d(TAG, "prevTimeSM: " + prevTimeSM + "; prevLabel: " + prevLabel);

        postTimeSM = scanSM.nextLong();
        postLabel = scanSM.nextInt();

        Log.d(TAG, "postTimeSM: " + postTimeSM + "; postLabel: " + postLabel);

        // each window has unique label
        windowData.clean();

        // search windowData beginning
        // assumption: register only label>0  -->  IGNORE<=0
        while (prevLabel > 0) {

          if (timeSD < 0) {
            if (!scanSD.hasNextLong()) {
              break;
            }
            timeSD = scanSD.nextLong();
          }

          // used to calculate hz
          lastTimeSD = timeSD;
          if (firstTimeSD < 0) firstTimeSD = timeSD;

          if (timeSD >= prevTimeSM) {
            if (timeSD <= postTimeSM) {
              Log.d(TAG, "timeSD: " + timeSD);

              // add x y z to windowData
              float[] linearAccel = {scanSD.nextFloat(), scanSD.nextFloat(), scanSD.nextFloat()};

              if (windowData.addData((float) vecLength(linearAccel))) {
                // we have a complete windowData

                // calculate features
                float[] features = myFeatures.getFeatures(windowData);

                // save to libsvm file with the correct label
                String[] textToFile = new String[1];
                textToFile[0] = prevLabel + " ";
                for (int i = 0; i < features.length; i++) {
                  textToFile[0] += (i + 1) + ":" + features[i] + " ";
                }
                MyUtil.writeToSDFile(textToFile, outFolder, outFile, true);
              }

              if (scanSD.hasNextLine()) {
                scanSD.nextLine();
                intent = new Intent("com.example.activityregistrator.UPDATE_PROGRESS");
                intent.putExtra("progress", (float) ((++done) / total) * 100);
                context.sendBroadcast(intent);
                timeSD = -1l; // get nextLong()
              } else {
                break;
              }
            } else {
              break;
            }
          } else {
            if (scanSD.hasNextLine()) {
              scanSD.nextLine();
              intent = new Intent("com.example.activityregistrator.UPDATE_PROGRESS");
              intent.putExtra("progress", (float) ((++done) / total) * 100);
              context.sendBroadcast(intent);
              timeSD = -1l; // get nextLong()
            } else {
              break;
            }
          }
        }

        prevTimeSM = postTimeSM;
        prevLabel = postLabel;
      }
    }

    scanSD.close();
    scanSM.close();

    Intent intent = new Intent("com.example.activityregistrator.UPDATE_HZ");
    intent.putExtra("hz", done / (((float) (lastTimeSD - firstTimeSD)) / 1000f));
    context.sendBroadcast(intent);

    Log.d(TAG, "[firstTimeSD,lastTimeSD,done]: " + firstTimeSD + " " + lastTimeSD + " " + done);

    return true;
  }