예제 #1
0
  /** @param args the command line arguments */
  public static void main(String[] args) {
    // TODO code application logic here
    // Iniciar consoler
    Console c;
    c = System.console();
    if (c == null) {
      System.out.println("Vc precisa estar no prompt!");
      System.exit(1);
    }

    // Variaveis
    float time_a[] = new float[5];
    float time_b[] = new float[5];
    int i;
    float menor_a = 1000, maior_a = 0, menor_b = 1000, maior_b = 0, media_a = 0, media_b = 0;

    // Entrada
    for (i = 0; i < 5; i++) {
      time_a[i] = Float.parseFloat(c.readLine("\nInforme a altura (" + (i + 1) + ") do time a: "));

      if (time_a[i] < menor_a) {
        menor_a = time_a[i];
      }

      if (time_a[i] > maior_a) {
        maior_a = time_a[i];
      }

      media_a += time_a[i];
    }
    media_a = media_a / 5;

    for (i = 0; i < 5; i++) {
      time_b[i] = Float.parseFloat(c.readLine("\nInforme a altura (" + (i + 1) + ") do time b: "));

      if (time_b[i] < menor_b) {
        menor_b = time_b[i];
      }

      if (time_b[i] > maior_b) {
        maior_b = time_b[i];
      }

      media_b += time_b[i];
    }
    media_b = media_b / 5;

    // Saida
    System.out.println("A menor do time a eh: " + menor_a);
    System.out.println("A maior do time a eh: " + maior_a);
    System.out.println("A media do time a eh: " + media_a);
    System.out.println("A menor do time b eh: " + menor_b);
    System.out.println("A maior do time b eh: " + maior_b);
    System.out.println("A media do time b eh: " + media_b);
  }
예제 #2
0
 public void removePlayer() {
   String playerName = con.readLine("Enter player's name: ");
   String teamName = con.readLine("Enter player's team: ");
   Team t = (Team) cache.get(encode(teamName));
   if (t != null) {
     t.removePlayer(playerName);
     cache.put(encode(teamName), t);
   } else {
     con.printf(msgTeamMissing, teamName);
   }
 }
예제 #3
0
 public void addPlayers() {
   String teamName = con.readLine(msgEnterTeamName);
   String playerName = null;
   Team t = (Team) cache.get(encode(teamName));
   if (t != null) {
     while (!(playerName = con.readLine("Enter player's name (to stop adding, type \"q\"): "))
         .equals("q")) {
       t.addPlayer(playerName);
     }
     cache.put(encode(teamName), t);
   } else {
     con.printf(msgTeamMissing, teamName);
   }
 }
 @Override
 public void setValue(Console console) {
   String value = console.readLine("%s", getPrompt().getText()); // $NON-NLS-1$
   if ((value != null) && !StringUtils.EMPTY.equals(value)) {
     getHolder().setValue(value);
   }
 }
예제 #5
0
  public static void main(String[] args) {
    Console myConsole = System.console();

    System.out.println("Please enter a number greater than 0!");
    String stringNumber = myConsole.readLine();
    Integer number = Integer.parseInt(stringNumber);

    ArrayList<String> allEntries = new ArrayList<String>();

    for (Integer i = 1; i <= number; i++) {

      String currentEntry = pingPongMethod(i);
      allEntries.add(currentEntry);

      //
      //
      // if(i % 3 == 0 && i % 5 == 0) {
      //   allEntries.add("ping-pong");
      // } else if (i % 3 == 0) {
      //   allEntries.add("ping");
      // } else if (i % 5 == 0 ) {
      //     allEntries.add("pong");
      // } else {
      //     String numbers = Integer.toString(i);
      //     allEntries.add(numbers);
      //     }
      //
      //
      //   }
      //   System.out.println(allEntries);
    }
  }
  // main method not found. runtime error. main method signature is not proper
  public static void main(String[] args) {

    Console mconsole = System.console();

    // error: cannot find symbol
    String firstName = mconsole.readLine("What is your name");
  }
예제 #7
0
  /** @param args the command line arguments */
  public static void main(String[] args) {
    // TODO code application logic here
    Console c;
    c = System.console();

    // Variaveis
    int n = 1;
    int x = 0;
    String str_n;

    while (n != 0) {
      // Entrada
      str_n = c.readLine("\nDigite um numero (digite 0 para sair):  ");

      // Conversão

      n = Integer.parseInt(str_n);

      x = n % 2;

      switch (x) {
        case 0:
          System.out.println("Par");
          break;
        case 1:
          System.out.println("Impar");
          break;
        default:
          break;
      }
    }
  }
  public static void main(String[] arg) {
    Console myConsole = System.console();

    System.out.println("what is your favorite number");
    String favoriteNumber = myConsole.readLine();
    System.out.println("Your favorite number is " + favoriteNumber + "? Me Too!");
  }
예제 #9
0
  /**
   * Main driver - run this to start interactive password manager.
   *
   * @param args Prog args
   * @throws Throwable If something went very wrong.
   */
  public static void main(String[] args) throws Throwable {
    Console c = System.console();
    if (c == null) FError.errAndExit("You need to be running in CLI mode");

    c.printf(
        "Welcome to FLogin!%nThis utility will encrypt & store your usernames/passwords%n(c) 2016 Fastily%n%n");

    // let user enter user & pw combos
    HashMap<String, String> ul = new HashMap<>();
    while (true) {
      String u = c.readLine("Enter a username: "******"!!! Characters hidden for security !!! %n");
      char[] p1 = c.readPassword("Enter password for %s: ", u);
      char[] p2 = c.readPassword("Confirm/Re-enter password for %s: ", u);

      if (Arrays.equals(p1, p2)) ul.put(u, new String(p1));
      else c.printf("Entered passwords do not match!%n");

      if (!c.readLine("Continue? (y/N): ").trim().toLowerCase().matches("(?i)(y|yes)")) break;

      c.printf("%n");
    }

    if (ul.isEmpty()) FError.errAndExit("You didn't enter any user/pass.  Program will exit.");

    // Generating our JSONObject
    JSONObject jo = new JSONObject();
    for (Map.Entry<String, String> e : ul.entrySet()) {
      JSONObject internal = new JSONObject();
      internal.put("pass", e.getValue());
      jo.put(e.getKey(), internal);
    }

    // Encrypt and dump to file
    KeyGenerator kg = KeyGenerator.getInstance("AES");
    kg.init(128);
    SecretKey sk = kg.generateKey();
    writeFiles(pf, sk.getEncoded());

    Cipher cx = Cipher.getInstance("AES");
    cx.init(Cipher.ENCRYPT_MODE, sk);
    writeFiles(px, cx.doFinal(jo.toString().getBytes("UTF-8")));

    c.printf(
        "Successfully written out to '%s', '%s', '%s%s' and '%s%s'%n",
        pf, px, homefmt, pf, homefmt, px);
  }
예제 #10
0
  private void readDataConsole() {
    Console c = System.console();
    if (c == null) {
      System.err.println("No console.");
      System.exit(1);
    }

    String login = c.readLine("Enter your login: ");
  }
예제 #11
0
  // creating our own method
  // type declaration
  public static void askWhatYouAteForMeal(String meal) {

    // create console variable
    Console myConsole = System.console();

    System.out.println("What did you eat for " + meal + "?");
    String food = myConsole.readLine();
    System.out.println("You had " + food + " for " + meal + "!");
  }
예제 #12
0
 public static void main(String[] args) {
   Console c = System.console();
   char[] pw;
   if (c == null) {
     return;
   }
   pw = c.readPassword("%s", "pw: ");
   System.out.println(c.readLine("%s", "input: "));
 }
예제 #13
0
  public static String readFromStdin(boolean isEcho) throws IOException {
    // int len = System.in.read(STDIN_BUFFER);
    // return new String(STDIN_BUFFER, 0, len).trim();

    if (isEcho) {
      return console.readLine().trim();
    }
    return new String(console.readPassword()).trim();
  }
예제 #14
0
파일: SrampWagon.java 프로젝트: rnc/s-ramp
 /** Prompts the user to enter a username for authentication credentials. */
 private String promptForUsername() {
   Console console = System.console();
   if (console != null) {
     return console.readLine(Messages.i18n.format("USERNAME_PROMPT")); // $NON-NLS-1$
   } else {
     System.err.println(Messages.i18n.format("NO_CONSOLE_ERROR_1")); // $NON-NLS-1$
     return null;
   }
 }
예제 #15
0
  public static void main(String argv[]) {

    Console console = System.console();
    String username = console.readLine("Username: "******"Password: "******"Entered password: " + new String(password));
    // clear the array as soon as the password has been used
    Arrays.fill(password, ' ');
  }
예제 #16
0
 public void sendMessage() throws Exception {
   String userInput;
   userInput = console.readLine();
   JPacket packet = new JPacket(userInput);
   com.sendMessage(packet);
   if (userInput.equals("End Chat")) {
     endChat();
     System.out.println("Chat Over");
   } else logMessage(packet, "You");
 }
예제 #17
0
  public static void main(String[] args) {

    // Create a console object.
    Console objConsole = System.console();
    if (objConsole != null) {

      // readLine method call.
      String userName = objConsole.readLine("Enter  username  : "******"You have entered : " + userName);
    }
  }
예제 #18
0
 public static void main(String[] args) {
   Console console = System.console();
   if (console != null) {
     String user = new String(console.readLine("Enter username:"******"Enter password"));
     console.printf("User name is " + user + "\n");
     console.printf("Password is " + pwd + "\n");
   } else {
     System.out.println("Console is unavaliable");
   }
 }
예제 #19
0
 public static void main(String args[]) {
   System.out.println("----- Client Start -----");
   Console in = System.console();
   // get a name
   String username = in.readLine("Enter your name: ");
   // get server hostname
   String hostname = in.readLine("Server hostname: ");
   // c or j
   String mode = in.readLine("[C]reate or [J]oin?: ");
   // get room name
   String roomname = in.readLine("Name of game-room: ");
   // set up the demopanel and its enclosing frame
   DemoPanel ui = new DemoPanel();
   JFrame frame = new JFrame("ateam-tanks");
   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   frame.setSize(500, 500);
   frame.setLayout(new BorderLayout());
   frame.add(ui, BorderLayout.CENTER);
   frame.addKeyListener(ui);
   frame.setVisible(true);
   // init and start game client
   GameClient c1 = new GameClient(username, 8887);
   // create RealWindow
   RealWindow win = new RealWindow(c1, ui);
   // start server communications
   try {
     sleep(1000);
     System.out.println("Connecting to server..");
     c1.push(new event.client.JoinServerEvent(hostname));
     sleep(1000);
     if (mode.equals("C") || mode.equals("c")) {
       c1.push(new event.client.FwdUserEvent(new event.user.CreateRoomEvent(roomname, mkList())));
       in.readLine("Press Enter to start the game");
       c1.push(new event.client.FwdUserEvent(new event.user.StartGameEvent()));
     } else if (mode.equals("J") || mode.equals("j")) {
       c1.push(new event.client.FwdUserEvent(new event.user.JoinRoomEvent(roomname)));
     }
   } catch (InterruptedException e) {
   }
 }
예제 #20
0
 /**
  * Prompt user for yes/no answer
  *
  * @param message The message to display
  * @param defaultValue The default answer if there's no console or if "Enter" key is pressed.
  * @param objects Parameters to use in the message (like in {@link String#format(String,
  *     Object...)})
  * @return "true" if answer is "yes" or "y", else "false".
  */
 protected String readConsole(String message, String defaultValue, Object... objects) {
   String answer;
   Console console = System.console();
   if (console == null || StringUtils.isEmpty(answer = console.readLine(message, objects))) {
     answer = defaultValue;
   }
   answer = answer.trim().toLowerCase();
   if ("yes".equals(answer) || "y".equals(answer)) {
     return "true";
   } else {
     return "false";
   }
 }
예제 #21
0
 public void addTeam() {
   String teamName = con.readLine(msgEnterTeamName);
   @SuppressWarnings("unchecked")
   List<String> teams = (List<String>) cache.get(encode(teamsKey));
   if (teams == null) {
     teams = new ArrayList<String>();
   }
   Team t = new Team(teamName);
   cache.put(encode(teamName), t);
   teams.add(teamName);
   // maintain a list of teams under common key
   cache.put(teamsKey, teams);
 }
예제 #22
0
 public static void main(String[] args) {
   Set<Character> hole1 = new HashSet<Character>();
   Set<Character> hole2 = new HashSet<Character>();
   hole1.add('A');
   hole1.add('D');
   hole1.add('O');
   hole1.add('P');
   hole1.add('R');
   hole1.add('Q');
   hole2.add('B');
   Console c = System.console();
   int n = Integer.parseInt(c.readLine());
   for (int i = 0; i < n; i++) {
     int count = 0;
     String s = c.readLine();
     for (int j = 0; j < s.length(); j++) {
       if (hole1.contains(s.charAt(j))) count++;
       else if (hole2.contains(s.charAt(j))) count += 2;
     }
     System.out.println(count + "");
   }
 }
예제 #23
0
  private void initiateQuery() {
    Console console = System.console();
    String input = console.readLine("Please enter search term: ");
    while (input.isEmpty()) {
      input = console.readLine("Please enter a valid search term: ");
    }

    String precision = console.readLine("Please enter desired precision(between 0 and 1): ");
    while (precision.isEmpty() || !isPrecisionValid(precision)) {
      precision = console.readLine("Please enter a valid precision(between 0 and 1): ");
    }

    boolean complete = false;

    while (!complete) {
      try {
        String bingResults = searchBing(input);
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

      SearchResult[] searchResults = parseTenSearchResults(bingResults);
      int numOfRelevant = 0;
      for (SearchResult result : searchResults) {
        boolean relevant = isResultRelevant(result);
        if (relevant) {
          numOfRelevant++;
        }
      }

      if (numOfRelevant < (Double.parseDouble(precision) * 10)) {
        String[] additionalTerms = extractNewTerms(searchResults);
      } else {
        complete = true;
      }
    }
  }
예제 #24
0
  public static void main(String[] args) {
    Console myConsole = System.console();

    System.out.println("How old are you?");
    String stringUserAge = myConsole.readLine();
    Integer integerUserAge = Integer.parseInt(stringUserAge);

    /* BOOLEAN used in IF statement */
    if (integerUserAge >= 17) {
      System.out.println("You can see the movie.");
    } else {
      System.out.println("I'm sorry, you are too young to see that movie.");
    }
  }
예제 #25
0
  public static void main(String[] args) throws IOException {
    System.out.println("Welcome to the coding console!");
    MasterPasswordStore.readFromConsole();
    ConfigurationValueCoder valueCoder = new ConfigurationValueCoder();

    Console console = System.console();
    while (true) {
      System.out.println("1. encode values");
      System.out.println("2. decode values");
      System.out.println("3. exit");
      String choice = console.readLine();
      if ("1".equals(choice)) {
        String text = console.readLine("Text: ");
        System.out.println(valueCoder.encode(text));
      } else if ("2".equals(choice)) {
        String text = console.readLine("Text: ");
        System.out.println(valueCoder.decode(text));
      }
      if ("3".equals(choice)) {
        return;
      }
    }
  }
예제 #26
0
  public static void main(String[] args) throws IOException {
    InvertedIndex invertedIndex = new InvertedIndex();
    if (args.length != 1) {
      System.out.println("Usage: java -jar InvertedIndexMain.jar <file>");
      System.exit(1);
    }
    invertedIndex.buildFromTextFile(args[0]);
    Console console = System.console();

    /**
     * Loop through queries. Return "No hits!" if query String has no results. Use exit! to exit the
     * loop and programm. If query has a result, print result and highlight the query words.
     */
    EvaluateBenchmark bench = new EvaluateBenchmark(invertedIndex);
    bench.readBenchmarkFile();

    while (true) {
      String query =
          console
              .readLine(
                  "Enter your search"
                      + " query (separate words with spaces, enter exit! to leave):")
              .toLowerCase();

      if (query.equals("exit!")) {
        break;
      }

      String[] words = query.split("\\W+");

      ArrayList<Pair> queryResult = invertedIndex.processQuery(words);

      if (queryResult.isEmpty() || query.isEmpty()) {
        System.out.println("No hits!");
      } else {
        for (int i = 0; i < 3 && i < queryResult.size(); i++) {
          int docId = queryResult.get(i).documentId;
          String text = invertedIndex.documents.get(docId - 1);
          String ansiRed = "\u001B[31m";
          String ansiReset = "\u001B[0m";
          for (String word : words) {
            text = text.replaceAll("((?i)" + word + ")", ansiRed + "$1" + ansiReset);
          }
          System.out.println("\n" + text + "\n");
          queryResult.get(i).prettyPrint();
        }
      }
    }
  }
예제 #27
0
 public void removeTeam() {
   String teamName = con.readLine(msgEnterTeamName);
   Team t = (Team) cache.get(encode(teamName));
   if (t != null) {
     cache.remove(encode(teamName));
     @SuppressWarnings("unchecked")
     List<String> teams = (List<String>) cache.get(teamsKey);
     if (teams != null) {
       teams.remove(teamName);
     }
     cache.put(teamsKey, teams);
   } else {
     con.printf(msgTeamMissing, teamName);
   }
 }
예제 #28
0
  public static void main(String[] args) {
    Console console = System.console();
    if (console == null) {
      System.err.println("No console.");
      System.exit(1);
    }
    while (true) {

      Pattern pattern = Pattern.compile(console.readLine("%nEnter your regex: "));

      Matcher matcher = pattern.matcher(console.readLine("Enter input string to search: "));

      boolean found = false;
      while (matcher.find()) {
        console.format(
            "I found the text" + " \"%s\" starting at " + "index %d and ending at index %d.%n",
            matcher.group(), matcher.start(), matcher.end());
        found = true;
      }
      if (!found) {
        console.format("No match found.%n");
      }
    }
  }
예제 #29
0
  /** @param args the command line arguments */
  public static void main(String[] args) {
    // TODO code application logic here

    // Variaveis
    int n = 0, i;
    float media = 0f, nota = 0f;

    // Iniciar Consoler
    Console c = System.console();

    if (c == null) {
      System.out.println("Vc precisa estar no prompt!");
      System.exit(1);
    }

    // n
    n = Integer.parseInt(c.readLine("Quantos alunos?"));
    for (i = 0; i < n; i++) {
      nota = Float.parseFloat(c.readLine("Informe nota (" + i + ")"));
      media += nota;
    }
    media = media / n;
    System.out.println("A media eh: " + media);
  }
 public static String readLine(String msg) {
   String answer = "";
   Console console = null;
   try {
     console = System.console();
   } catch (Exception ex) {
   }
   if (console != null) {
     try {
       answer = console.readLine(msg);
     } catch (Exception ex) {
     }
   }
   return answer;
 }