Пример #1
0
  public static void main(String[] args) {
    // Object for input
    Scanner keyboard = new Scanner(System.in);
    boolean doesMatch; // boolean return value for checkNumbers()
    int numberCounter = 0; // counter for guesses
    Numbers game = new Numbers(); // object for Numbers

    // First guess input
    System.out.println("Enter your guess: ");
    int userGuess = keyboard.nextInt();

    numberCounter++;
    // check to see if the user continues the game
    doesMatch = game.checkNumbers(userGuess);
    // The main game

    while (numberCounter < 6) {

      if (doesMatch) {
        // if continues, guesses again
        System.out.println("Enter your next guess: ");
        userGuess = keyboard.nextInt();
        numberCounter++;
        // check to see if the user continues the game
        doesMatch = game.checkNumbers(userGuess);
      }
      // if incorrect guess quits the game
      if (!doesMatch) {
        System.out.println("You have destroyed the world!");
        return;
      }
    }

    System.out.println("You have saved the world!");
  }
Пример #2
0
  @Test
  public void testNearlyEqual() throws Exception {

    double a = 1.000001;
    double b = 0.000001;
    double c = a - b;
    assertTrue(Numbers.nearlyEqual(1.0, c, 1));
  }
Пример #3
0
 public static int compare(Object k1, Object k2) {
   if (k1 == k2) return 0;
   if (k1 != null) {
     if (k2 == null) return 1;
     if (k1 instanceof Number) return Numbers.compare((Number) k1, (Number) k2);
     return ((Comparable) k1).compareTo(k2);
   }
   return -1;
 }
 @SubL(source = "cycl/subl-macros.lisp", position = 14186)
 public static final SubLObject do_sequence_index_doneP(
     SubLObject index, SubLObject end_index, SubLObject sequence) {
   if (sequence.isList()) {
     return Types.sublisp_null(sequence);
   } else {
     return Numbers.numE(index, end_index);
   }
 }
Пример #5
0
 public static boolean equiv(Object k1, Object k2) {
   if (k1 == k2) return true;
   if (k1 != null) {
     if (k1 instanceof Number && k2 instanceof Number)
       return Numbers.equal((Number) k1, (Number) k2);
     else if (k1 instanceof IPersistentCollection || k2 instanceof IPersistentCollection)
       return pcequiv(k1, k2);
     return k1.equals(k2);
   }
   return false;
 }
Пример #6
0
 protected void onDraw(Canvas canvas) {
   for (int i = 0;
       i < 5;
       i++) // Tramite i due cicli for annidati,e il metodo "onDraw" si disegnano tutti i pulsanti
     // della griglia
     for (int j = 0;
         j < 6;
         j++) // di gioco, infatti si passano come parametri il bitmap in posizione [i][j] e il
     // relativo bound
     {
       canvas.drawBitmap(griglia.getBitmap(i, j), null, griglia.getBound(i, j), null);
     }
   canvas.drawBitmap(
       numbers.getNumbers()[0],
       null,
       numbers.getBound()[0],
       null); // Si disegnano sullo schermo i due numeri relativi al contatore e al cronometro
   canvas.drawBitmap(numbers.getNumbers()[1], null, numbers.getBound()[1], null);
   canvas.drawBitmap(numbers2.getNumbers()[0], null, numbers2.getBound()[0], null);
   canvas.drawBitmap(numbers2.getNumbers()[1], null, numbers2.getBound()[1], null);
   canvas.drawBitmap(
       griglia.getBigBitmap(),
       null,
       griglia.getBigBound(),
       null); // Si disegna sullo schermo il pulsante centrale
 }
Пример #7
0
 <T extends Composite> T parse(String stringText, Class<T> compositeClass)
     throws ParsingException, IllegalAccessException, InstantiationException {
   T type;
   try {
     type = compositeClass.newInstance();
     Class componentClass = componentMap.get(compositeClass);
     Matcher matcher = patterns.get(componentClass).matcher(stringText);
     while (matcher.find()) {
       if (componentClass == SentenceToken.class) {
         if (matcher.group().matches(patterns.get(Word.class).toString())) {
           type.add(new Word(matcher.group()));
         }
         if (matcher.group().matches(patterns.get(Numbers.class).toString())) {
           Numbers number = new Numbers();
           number.add(new Integer(matcher.group()));
           type.add(number);
         }
         if (matcher.group().matches(patterns.get(Punctuation.class).toString())) {
           Punctuation punctuation = new Punctuation();
           punctuation.add(matcher.group().charAt(0));
           type.add(punctuation);
         }
         if (matcher.group().matches(patterns.get(Space.class).toString())) {
           Space space = new Space();
           space.add(matcher.group().charAt(0));
           type.add(space);
         }
       } else {
         Component c = parse(matcher.group(), componentClass);
         type.add(c);
       }
     }
     return type;
   } catch (InstantiationException | IllegalAccessException ignored) {
     logger.error("Could not parse the elements of text ");
     throw new ParsingException("Could not parse the elements of text ");
   }
 }
Пример #8
0
 @Override
 public boolean onTouchEvent(
     MotionEvent
         event) // Si sovrascrive il metodo "onTouchEvent" per gestire l'evento di touch nel modo
       // desiderato
     {
   float x = event.getX(); // Restituisce la coordinata x del "touch" sullo schermo
   float y = event.getY(); // Restituisce la coordinata y del "touch" sullo schermo
   int[] a =
       griglia.coord(
           x, y); // Il vettore a contiene gli indici del "pulsante" premuto sullo schermo
   int c =
       griglia.getBigColor(); // La variabile c, contiene il numero che rappresenta il colore del
   // pulsante premuto
   int p =
       griglia.getColor(
           a[0],
           a[1]); // La variabile p, contiene il numero che rappresenta il colore del pulsante
   // premuto
   if (p != c
       & p != 2) // Se il colore del pulsante centrale è diverso da quello del pulsante premuto
   { // e il contatore è diverso da 0, allora si decrementa il contatore
     if (contatore != 0) contatore--;
     numbers.display(contatore); // Si aggiorna il contatore sul display
     griglia.setGrayButton(a[0], a[1]); // Si imposta a grigio il pulsante premuto
     this.postInvalidate(); // Tramtite "postInvalidate()" si richiama il metodo "onDraw" e si
     // ridisegna la griglia
   } else if (p == c) // Se il pulsante premuto è uguale a quello centrale allora si incrementa di
   { // una unità il contatore
     contatore++;
     numbers.display(contatore); // Si aggiorna il contatore sul display
     griglia.setGrayButton(a[0], a[1]); // Si imposta a grigio il pulsante premuto
     this.postInvalidate(); // Tramtite "postInvalidate()" si richiama il metodo "onDraw" e si
     // ridisegna la griglia
   }
   return true;
 }
Пример #9
0
  public AdaptiveHyperLogLog(int[] buckets) {
    checkArgument(Numbers.isPowerOf2(buckets.length), "numberOfBuckets must be a power of 2");

    estimator = makeEstimator(buckets);
  }
Пример #10
0
  public AdaptiveHyperLogLog(int numberOfBuckets) {
    Preconditions.checkArgument(
        Numbers.isPowerOf2(numberOfBuckets), "numberOfBuckets must be a power of 2");

    this.estimator = new SparseEstimator(numberOfBuckets);
  }
Пример #11
0
 public void timeUpdate(int a) {
   numbers2.display(a);
 }
Пример #12
0
 public PbInt(Long value) {
   super(Numbers.serializeLong(value));
 }
Пример #13
0
  private void writeDiscardFile(long rowid) throws JournalException {

    if (discardTxtRaf == null) {
      try {
        discardTxtRaf = new RandomAccessFile(discardTxt, "rw");
        discardTxtRaf.getChannel();
        discardSink =
            new FlexBufferSink(
                discardTxtRaf.getChannel().position(discardTxtRaf.getChannel().size()),
                1024 * 1024);
      } catch (IOException e) {
        throw new JournalException(e);
      }
    }

    JournalMetadata m = getMetadata();
    int p = Rows.toPartitionIndex(rowid);
    long row = Rows.toLocalRowID(rowid);
    long rowCount = 0;

    try {
      // partitions
      for (int n = getPartitionCount() - 1; p < n; p++) {
        final Partition partition = getPartition(n, true);
        // partition rows
        for (long r = row, psz = partition.size(); r < psz; r++) {
          // partition columns
          for (int c = 0, cc = m.getColumnCount(); c < cc; c++) {
            switch (m.getColumnQuick(c).type) {
              case DATE:
                Dates.appendDateTime(discardSink, partition.getLong(r, c));
                break;
              case DOUBLE:
                Numbers.append(discardSink, partition.getDouble(r, c), 12);
                break;
              case FLOAT:
                Numbers.append(discardSink, partition.getFloat(r, c), 4);
                break;
              case INT:
                Numbers.append(discardSink, partition.getInt(r, c));
                break;
              case STRING:
                partition.getStr(r, c, discardSink);
                break;
              case SYMBOL:
                discardSink.put(partition.getSym(r, c));
                break;
              case SHORT:
                Numbers.append(discardSink, partition.getShort(r, c));
                break;
              case LONG:
                Numbers.append(discardSink, partition.getLong(r, c));
                break;
              case BYTE:
                Numbers.append(discardSink, partition.getByte(r, c));
                break;
              case BOOLEAN:
                discardSink.put(partition.getBool(r, c) ? "true" : "false");
                break;
            }

            if (((++rowCount) & 7) == 0) {
              discardSink.flush();
            }
          }
        }
      }
    } finally {
      discardSink.flush();
    }
  }