Example #1
0
 public static void writeText(String s) {
   FileWriter fWriter = null;
   BufferedWriter writer = null;
   try {
     fWriter = new FileWriter("info.txt", true);
     writer = new BufferedWriter(fWriter);
     writer.append(s);
     writer.newLine();
     writer.close();
   } catch (Exception e) {
   }
 }
  private void setPollerConfiguration(PollerConfiguration pollconfig) {
    try {
      pollconfig.validate();

      BufferedWriter bw =
          new BufferedWriter(
              new FileWriter(
                  WTProperties.getValue("SNMPConfig.directory") + "poller-configuration.xml"));
      pollconfig.marshal(bw);
      bw.flush();
      bw.close();
    } catch (MarshalException me) {
      me.printStackTrace();
    } catch (ValidationException ve) {
      ve.printStackTrace();
    } catch (IOException ioe) {
      ioe.printStackTrace();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  private static void generateKML(boolean isHighway) {
    System.out.println("generate link kml...");
    try {
      FileWriter fstream =
          new FileWriter(root + "/" + (isHighway ? highwayKmlFile : arterialKmlFile));
      BufferedWriter out = new BufferedWriter(fstream);
      out.write("<kml><Document>");
      ArrayList<LinkInfo> linkList = isHighway ? highwayLinkList : arterialLinkList;
      for (int i = 0; i < linkList.size(); i++) {
        LinkInfo link = linkList.get(i);
        int linkId = link.getLinkId();
        int funcClass = link.getFuncClass();
        String streetName = link.getStreetName();
        if (streetName.contains("&")) streetName = streetName.replaceAll("&", " and ");
        ArrayList<PairInfo> nodeList = link.getNodeList();

        String kmlStr = "<Placemark><name>Link:" + linkId + "</name>";
        kmlStr += "<description>";
        kmlStr += "Class:" + funcClass + "\r\n";
        kmlStr += "Name:" + streetName + "\r\n";
        kmlStr += "</description>";
        kmlStr += "<LineString><tessellate>1</tessellate><coordinates>";
        for (int j = 0; j < nodeList.size(); j++) {
          PairInfo node = nodeList.get(j);
          kmlStr += node.getLongi() + "," + node.getLati() + ",0 ";
        }
        kmlStr += "</coordinates></LineString></Placemark>\n";

        out.write(kmlStr);
      }
      out.write("</Document></kml>");
      out.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
    System.out.println("generate link kml finish!");
  }
Example #4
0
  public static void main(String args[]) {
    Date now = new Date();
    DateFormat df = DateFormat.getDateInstance();
    String component = "Component : " + args[0];
    String date = "Date : " + df.format(now);
    ;
    String version = "Version : " + args[1];

    try {
      FileWriter fstream = new FileWriter("packInfo.txt");
      BufferedWriter out = new BufferedWriter(fstream);
      out.write(component);
      out.newLine();
      out.write(date);
      out.newLine();
      out.write(version);
      out.close();
    } catch (Exception e) {
      System.err.println("Error in opening a file");
    }
  }
  public static void main(String[] args) {
    try {
      DocumentBuilderFactory db = DocumentBuilderFactory.newInstance();
      DocumentBuilder builder = db.newDocumentBuilder();
      Document dom = builder.parse("data/geographic-area-data.html");
      XPathFactory xpath = XPathFactory.newInstance();
      XPath path = xpath.newXPath();
      XPathExpression table =
          path.compile("//div[@id='mw-content-text']/table[contains(@class,'wikitable')]/tr");
      NodeList wikiData = (NodeList) table.evaluate(dom, XPathConstants.NODESET);

      NodeList children;
      String currentData, cleanData;

      /* Open output stream */
      FileWriter fstream = new FileWriter("data/parsed.yaml");
      BufferedWriter out = new BufferedWriter(fstream);

      for (int i = 0; i < wikiData.getLength(); i++) {
        if (i == 0) {
          continue;
        }
        out.write(new Integer(i).toString() + ":\n");
        children = wikiData.item(i).getChildNodes();
        for (int j = 0; j < children.getLength(); j++) {
          currentData = (String) children.item(j).getTextContent();
          switch (j) {
            case 0:
              /* Current Data is empty */
              break;
            case 1:
              cleanData = decompose(currentData).trim().replaceAll("[^a-zA-Z\\s]+", "");
              out.write("\t\"Geographic entity\": \"" + cleanData + "\"\n");
              break;
            case 2:
              /* Current Data is empty */
              break;
            case 3:
              cleanData = decompose(currentData).trim().replaceAll(",", "");
              out.write("\t\"Area\": \"" + cleanData + "\"\n");
              break;
            case 4:
              /* Current Data is empty */
              break;
            case 5:
              cleanData = decompose(currentData).trim();
              out.write("\t\"Notes\": \"" + cleanData + "\"\n");
              break;
            case 6:
              /* Current Data is empty */
              break;
            default:
              /* System.out.println("[" + j + "] Hit default case statement. Current Data is: " + currentData); */
              break;
          }
        }
      }
      /* Close output stream */
      out.close();
    } catch (Exception e) {
      System.out.println(e);
    }
  }
  public void printWeightUpdate() {

    String fileName = "WeightFile.txt";
    try {

      FileWriter fileWriter = new FileWriter(fileName);

      BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);

      System.out.println(
          "printWeightUpdate, put this i trainedWeights() and set isTrained to true");
      // weights for the hidden layer
      for (Neuron n : hiddenLayer) {
        ArrayList<Connection> connections = n.getAllInConnections();
        for (Connection con : connections) {
          String w = df.format(con.getWeight());
          System.out.println(
              "weightUpdate.put(weightKey(" + n.id + ", " + con.id + "), " + w + ");");

          bufferedWriter.write(ef.format(n.id));
          bufferedWriter.write(" ");
          bufferedWriter.write(ef.format(con.id));
          bufferedWriter.write(" ");
          bufferedWriter.write(w);
          bufferedWriter.newLine();
        }
      }
      // weights for the output layer
      for (Neuron n : outputLayer) {
        ArrayList<Connection> connections = n.getAllInConnections();
        for (Connection con : connections) {
          String w = df.format(con.getWeight());
          System.out.println(
              "weightUpdate.put(weightKey(" + n.id + ", " + con.id + "), " + w + ");");

          bufferedWriter.write(ef.format(n.id));
          bufferedWriter.write(" ");
          bufferedWriter.write(ef.format(con.id));
          bufferedWriter.write(" ");
          bufferedWriter.write(w);
          bufferedWriter.newLine();
        }
      }
      System.out.println();
      bufferedWriter.close();
    } catch (IOException ex) {

      System.out.println("Error writing to file " + fileName);
    }
  }
  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();
  }
Example #8
0
  public static String generateRoster()
  {
    String rostere="";
       database.openBusDatabase();

       // get available drivers here ------
       int[] drivers = DriverInfo.getDrivers();
       int[] buses = BusInfo.getBuses();
       // SET weekly/daily/isBack times of all drivers to 0
       for (int index = 0; index < drivers.length; index++)
       {
         DriverInfo.setHoursThisWeek(drivers[index], 0);
         DriverInfo.setHoursThisDay(drivers[index], 0);
         DriverInfo.setIsBackTime(drivers[index], 0);
       } // for

       // Starting route 65, goes up to 68
       int route = 65;

       // Counting variables for stats
       int totalWeeklyTimes = 0;
       int totalSaturdayTimes = 0;
       int totalSundayTimes = 0;

       int totalTimes = 0;

       // Array that stores the duration of services of each route
       List<ArrayList<Integer>> routeServicesDuration = new ArrayList<ArrayList<Integer>>();

       // Array that stores the driver name/id at a SLOT "day/route/service"
       //List<ArrayList<ArrayList<Integer>>> slots = new ArrayList<ArrayList<ArrayList<Integer>>>();

       //for (int k = 65; k < 69; k++)
       //{
         //totalWeekdayServices = TimetableInfo.getNumberOfServices
         //                 (i, TimetableInfo.timetableKind.weekday);
         //routesServiceDuration = int[j][totalWeekdayServices];
       //}

       // Day range: 0-6 (Mon-Sun)
       int day = 0;
       //routeServicesDuration.add(new ArrayList<Integer>());
       TimetableInfo.timetableKind.weekday;
       while( day < 7) // change to <7 to include sat/sun
       {
         // SET daily/isBack times of all drivers to 0
         for (int index = 0; index < drivers.length; index++)
         {
           DriverInfo.setHoursThisDay(drivers[index], 0);
           DriverInfo.setIsBackTime(drivers[index], 0);

         } // for

         for (int index = 0; index < buses.length; index++)
         {
           BusInfo.setIsBackTime(buses[index], 0);
         }

         Sort.sortDrivers(drivers);

         if (day < 5)
         {
            kind = TimetableInfo.timetableKind.weekday;
         }
         else if (day == 5)
         {
            kind = TimetableInfo.timetableKind.saturday;
         }
         else
         {
            kind = TimetableInfo.timetableKind.sunday;
         }
           //routeServicesDuration.add(new ArrayList<Integer>());
           slots.add(new ArrayList<ArrayList<Integer>>());
           busSlots.add(new ArrayList<ArrayList<Integer>>());
           //slots.get(day).add(new ArrayList<Integer>());
           route=65;
        while (route <= 66) // add to include all routes
        {
           routeServicesDuration.add(new ArrayList<Integer>());
           //slots.add(new ArrayList<ArrayList<Integer>>());
           slots.get(day).add(new ArrayList<Integer>());
           busSlots.get(day).add(new ArrayList<Integer>());
           //slots.add(new ArrayList<ArrayList<Integer>>());
           //slots.get(day).add(new ArrayList<Integer>());

         //slots.get(day).add(new ArrayList<Integer>());
         //slots.get(day).get(route-65).add(0);
         //System.out.println(slots.get(day).get(route-65).get(0));

           int[] busStops = BusStopInfo.getBusStops(route);
         //totalWeekdayServicesForRoute = TimetableInfo.getNumberOfServices
         //                 (route, TimetableInfo.timetableKind.weekday);
         //totalWeekdayServices = totalWeekdayServices + totalWeekdayServicesForRoute;


         //TimetableInfo.timetableKind kind = TimetableInfo.timetableKind.weekday;

         //System.out.print("Weekday Services : ");
           int[] services = TimetableInfo.getServices(route,kind);
           for (int i=0;i<services.length;i++)
           {

             // Array that stores the service times
             int[] times = TimetableInfo.getServiceTimes(route,kind, i);

             // Calculating and storing the service's duration
             routeServicesDuration.get(route-65).add(times[times.length-1]-times[0]);


             //Integer toPrint = routeServicesDuration.get(route-65).get(i);
             //totalWeeklyTimes = totalWeeklyTimes + toPrint;
             //System.out.println("Duration of Service " + services[i] + "(" + route + "): "
             //                    + toPrint);

             // Index to go through all the drivers
             int index = 0;

             // Boolean variable to check if a driver is allocated to the service
             boolean driverNotAllocated = true;
             // Stupid variable to check if driver isBack to take another service
             // change it to int
             //int isBackTime = DriverInfo.getIsBackTime(drivers[index]);



             while (driverNotAllocated && index < drivers.length)
             {
               int hoursThisWeek = DriverInfo.getHoursThisWeek(drivers[index]);
               int hoursThisDay = DriverInfo.getHoursThisDay(drivers[index]);
               int isBackTime = DriverInfo.getIsBackTime(drivers[index]);

               // If driver's daily and weekly hours dont exceed the maximums(5h / 50h)
               // and he is back from the previous taken service (and he is available
               // - for iteration 3) then he can take this service slot.
               if( hoursThisDay + routeServicesDuration.get(route-65).get(i) < 300
                   && hoursThisWeek + routeServicesDuration.get(route-65).get(i) < 3000
                   && isBackTime < times[0])
               {
                 // System.out.println("Day: "+ day + " ,Route/Service: " + (route-65) + "/" + i);
                 slots.get(day).get(route-65).add(drivers[index]);
                 //System.out.println(slots.get(day).get(route-65).get(i));


                 // Update driver's daily and weekly hours (could do it for yearly too)
                 DriverInfo.setHoursThisWeek(drivers[index],
                         hoursThisWeek + routeServicesDuration.get(route-65).get(i));
                 DriverInfo.setHoursThisDay(drivers[index],
                         hoursThisDay + routeServicesDuration.get(route-65).get(i));

                 // Update isBackTime to service's end time
                 // 65-66 : end time is at Stockport so dont care
                 // 67-68 : to check
                 //isBackTime = times[times.length-1];
                 //System.out.println(times[times.length-1]);
                 DriverInfo.setIsBackTime(drivers[index], times[times.length-1]);
                 // Driver allocated successfully
                 driverNotAllocated = false;

//IAM
                 boolean busNotAllocated=true;
                 int bindex = 0;
                 // Now allocate a bus to that slot too // another 3d array? yes prolly
                 while (busNotAllocated)
                 {
                   int isBusBackTime = BusInfo.getIsBackTime(buses[bindex]);
                   if (isBusBackTime < times[0])
                   {
                     busSlots.get(day).get(route-65).add(buses[bindex]);
                     BusInfo.setIsBackTime(buses[bindex], times[times.length-1]);
                     // Bus allocated successfully
                     busNotAllocated = false;
                   }
                   bindex++;
                 }
               }
               index++;
             }
           }
         //}

         //System.out.println("\nTotal: " + TimetableInfo.getNumberOfServices(route, kind));
         //System.out.println("=================================================");
         //day++;

           route++;
         } // inner while
         day++;
       } // while
       route=65;
         System.out.println("=================================================");
         TimetableInfo.timetableKind dayKind;
try
{
// Create file
FileWriter fstream = new FileWriter("roster");
BufferedWriter out = new BufferedWriter(fstream);

         for(int dayIndex=0; dayIndex<7; dayIndex++ )
         {
           out.write("\n=================================================");
           rostere += "\n=================================================";
           switch(dayIndex)
           {
             case 0:
               System.out.println("Monday");
               out.write("\nMonday");
               rostere+="\nMonday";
               break;
             case 1:
               System.out.println("Tuesday");
               out.write("\nTuesday");
               rostere+="\nTuesday";
               break;
             case 2:
               System.out.println("Wednesday");
               out.write("\nWednesday");
               rostere+="\nWednesday";
               break;
             case 3:
               System.out.println("Thursday");
               out.write("\nThursday");
               rostere+="\nThursday";
               break;
             case 4:
               System.out.println("Friday");
               out.write("\nFriday");
               rostere+="\nFriday";
               break;
             case 5:
               System.out.println("Saturday");
               out.write("\nSaturday");
               rostere+="\nSaturday";
               break;
             case 6:
               System.out.println("Sunday");
               out.write("\nSunday");
               rostere+="\nSunday";
               break;
           }
           out.write("\n=================================================");
           rostere += "\n=================================================";
           if (day < 5)
           {
             dayKind = TimetableInfo.timetableKind.weekday;
           }
           else if (day == 5)
           {
             dayKind = TimetableInfo.timetableKind.saturday;
           }
           else
           {
             dayKind = TimetableInfo.timetableKind.sunday;
           }
           for (int routeIndex=0; routeIndex<2; routeIndex++)
           {
             int[] servicesS = TimetableInfo.getServices(route+routeIndex, dayKind);
             switch(routeIndex)
             {
               case 0:
                 System.out.println("Route 65:");
                 out.write("\nRoute 65:");
                 rostere+="\nRoute 65:";
                 break;
               case 1:
                 System.out.println("Route 66:");
                 out.write("\nRoute 66:");
                 rostere+="\nRoute 66:";
                 break;
               case 2:
                 System.out.println("Route 67:");
                 out.write("\nRoute 67:");
                 rostere+="\nRoute 67:";
                 break;
               case 3:
                 System.out.println("Route 68:");
                 out.write("\nRoute 68:");
                 rostere+="\nRoute 68:";
                 break;
             } // switch
             //System.out.println(servicesS.length);
             rostere+="\n=================================================";
             out.write("\n=================================================");

             for (int service=0; service<servicesS.length; service++)
             {
               int id = slots.get(dayIndex).get(routeIndex).get(service);
               int busID = busSlots.get(dayIndex).get(routeIndex).get(service);
               String name = DriverInfo.getName(id);
               System.out.println("\nRoute / Service: " + (routeIndex+route) + "/"
                                  + servicesS[service]
                                  + "\nDriver: "
                                  + name  + "\nBus:" + busID + "\n");
                       out.write("\nRoute / Service: " + (routeIndex+route) + "/"
                                  + servicesS[service]
                                  + "\nDriver: "
                                  + name + "\nBus:" + busID  + "\n");
                       rostere+="\nRoute / Service: " + (routeIndex+route) + "/"
                                  + servicesS[service]
                                  + "\nDriver: "
                                  + name + "\nBus:" + busID  + "\n";
               //System.out.println("Hours: " + DriverInfo.getHoursThisWeek(id)/60);
             }
             out.write("\n=================================================");
             System.out.println("=================================================");
           }
           //out.write("\n=================================================");
           //System.out.println("=================================================");
           //System.out.println("Successfull generation of roster.");
          // System.out.println("=================================================");
          // rostere+="\n=================================================";
           //out.write("\n=================================================");
         }
rostere+="\n=================================================";
out.write("\n=================================================");
rostere+="\nSuccessfull generation of roster.";
out.close();
  } // try
         catch (Exception e)
         {//Catch exception if any
               System.err.println("Error: " + e.getMessage());
         }
return rostere;
    } // generateRoster