Beispiel #1
0
 public void makeSHButtonActionPerformed(ActionEvent evt) {
   String name = "Stakeholder " + (this.stakeholders.size());
   boolean a, b, c, d, e;
   a = b = c = d = e = false;
   int random = (int) (Math.random() * 32);
   System.out.println(random);
   if (random >= 16) {
     a = true;
     random -= 16;
   }
   if (random >= 8) {
     b = true;
     random -= 8;
   }
   if (random >= 4) {
     c = true;
     random -= 4;
   }
   if (random >= 2) {
     d = true;
     random -= 2;
   }
   if (random >= 1) {
     e = true;
     random -= 1;
   }
   System.out.printf("Stakeholder(%s, ,%b,%b,%b,%b,%b)%n", name, a, b, c, d, e);
   Stakeholder s = new Stakeholder(name, "", a, b, c, d, e);
   stakeholders.add(s);
   pushAllSHButton.setText("Push " + stakeholders.size() + " to View");
 }
Beispiel #2
0
 public static String modify(String in) {
   in = in.toLowerCase();
   String returnString = "";
   for (int i = 0; i < in.length(); i++) {
     char current = in.charAt(i);
     // Repeat Random Amount
     if (current == 'a' || current == 'e' || current == 'i' || current == 'o' || current == 'u') {
       if (Math.random() > 0.5) returnString += vowel[(int) Math.random() * 5];
       else returnString += Character.toUpperCase(vowel[(int) Math.random() * 5]);
     } else {
       for (int j = 0; j < (int) Math.random() * 5 + 1; j++) {
         if (Math.random() > 0.5) returnString += current;
         else returnString += Character.toUpperCase(current);
       }
     }
   }
   return returnString;
 }
Beispiel #3
0
 public void makeRelationsButtonActionPerformed(ActionEvent evt) {
   System.out.println("In make relationships");
   int k = stakeholders.size();
   for (Iterator<Stakeholder> s = stakeholders.iterator(); s.hasNext(); ) {
     Stakeholder stakeholder = s.next();
     int place = (int) Math.pow(2.0, (double) k);
     int random = (int) (Math.random() * place);
     place /= 2;
     System.out.println(random);
     for (int i = k - 1; i >= 0; i--) {
       System.out.printf("if(%d >= %d)\n", random, place);
       if (random >= place) {
         System.out.printf("%s.addI(%s)%n", stakeholder.getName(), stakeholders.get(i).getName());
         stakeholder.addInfluence(stakeholders.get(i).getName(), (int) (Math.random() * 4));
         random -= place;
       }
       place /= 2;
     }
   }
 }
Beispiel #4
0
 public synchronized void
     randomChoice() { // Metod koito opredeleq na proizvolen princip izbora na igracha i go zapisva
                      // v masiva.
   this.random = (int) (Math.random() * (max - min) + min);
   arr[this.nomer] = this.random;
   if (this.random == 1) {
     System.out.println("Izbora na igrach " + this.nomer + " e kamyk.");
   } else if (this.random == 2) {
     System.out.println("Izbora na igrach " + this.nomer + " e nojica.");
   } else {
     System.out.println("Izbora na igrach " + this.nomer + " e hartiq.");
   }
 }
 public void doPost(HttpServletRequest req, HttpServletResponse resp)
     throws ServletException, IOException {
   resp.getWriter().println("<HTML><BODY>");
   resp.getWriter().println(this + ": <br>");
   for (int c = 0; c < 10; c++) {
     resp.getWriter().println("Counter = " + counter + "<BR>");
     try {
       Thread.currentThread().sleep((long) Math.random() * 1000);
       counter++;
     } catch (InterruptedException exc) {
       exc.printStackTrace();
     }
   }
   resp.getWriter().println("</BODY></HTML>");
 }
Beispiel #6
0
  // Crear un array de dos dimensiones con valores aleatorios de dos digitos y transponer valores en
  // un segudo array
  static void transpo() {

    int numero = 98;
    int[][] valores1 = new int[5][4];
    int[][] valores2 = new int[4][5];

    for (int i = 0; i < valores1.length; i++) {

      for (int j = 0; j < valores1[i].length; j++) {

        valores1[i][j] = (int) (Math.random() * numero);
        System.out.println("valores1[" + i + "][" + j + "] = " + valores1[i][j]);
      }
    }

    for (int i = 0; i < valores2.length; i++) {

      for (int j = 0; j < valores2[i].length; j++) {

        valores2[i][j] = valores1[j][i];
        System.out.println("valores2[" + i + "][" + j + "] = " + valores2[i][j]);
      }
    }
  }
Beispiel #7
0
 public static int randInt(int min, int max) {
   return (min + (int) (Math.random() * ((max - min) + 1)));
 }
 // To add/remove functions change evaluateOperator() and registration
 public double evaluateFunction(String fncnam, ArgParser fncargs) throws ArithmeticException {
   switch (Character.toLowerCase(fncnam.charAt(0))) {
     case 'a':
       {
         if (fncnam.equalsIgnoreCase("abs")) {
           return Math.abs(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("acos")) {
           return Math.acos(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("asin")) {
           return Math.asin(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("atan")) {
           return Math.atan(fncargs.next());
         }
       }
       break;
     case 'c':
       {
         if (fncnam.equalsIgnoreCase("cbrt")) {
           return Math.cbrt(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("ceil")) {
           return Math.ceil(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("cos")) {
           return Math.cos(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("cosh")) {
           return Math.cosh(fncargs.next());
         }
       }
       break;
     case 'e':
       {
         if (fncnam.equalsIgnoreCase("exp")) {
           return Math.exp(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("expm1")) {
           return Math.expm1(fncargs.next());
         }
       }
       break;
     case 'f':
       {
         if (fncnam.equalsIgnoreCase("floor")) {
           return Math.floor(fncargs.next());
         }
       }
       break;
     case 'g':
       {
         //              if(fncnam.equalsIgnoreCase("getExponent"   )) { return
         // Math.getExponent(fncargs.next());                } needs Java 6
       }
       break;
     case 'l':
       {
         if (fncnam.equalsIgnoreCase("log")) {
           return Math.log(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("log10")) {
           return Math.log10(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("log1p")) {
           return Math.log1p(fncargs.next());
         }
       }
       break;
     case 'm':
       {
         if (fncnam.equalsIgnoreCase("max")) {
           return Math.max(fncargs.next(), fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("min")) {
           return Math.min(fncargs.next(), fncargs.next());
         }
       }
       break;
     case 'n':
       {
         //              if(fncnam.equalsIgnoreCase("nextUp"        )) { return Math.nextUp
         // (fncargs.next());                } needs Java 6
       }
       break;
     case 'r':
       {
         if (fncnam.equalsIgnoreCase("random")) {
           return Math.random();
         } // impure
         if (fncnam.equalsIgnoreCase("round")) {
           return Math.round(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("roundHE")) {
           return Math.rint(fncargs.next());
         } // round half-even
       }
       break;
     case 's':
       {
         if (fncnam.equalsIgnoreCase("signum")) {
           return Math.signum(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("sin")) {
           return Math.sin(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("sinh")) {
           return Math.sinh(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("sqrt")) {
           return Math.sqrt(fncargs.next());
         }
       }
       break;
     case 't':
       {
         if (fncnam.equalsIgnoreCase("tan")) {
           return Math.tan(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("tanh")) {
           return Math.tanh(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("toDegrees")) {
           return Math.toDegrees(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("toRadians")) {
           return Math.toRadians(fncargs.next());
         }
       }
       break;
     case 'u':
       {
         if (fncnam.equalsIgnoreCase("ulp")) {
           return Math.ulp(fncargs.next());
         }
       }
       break;
       // no default
   }
   throw new UnsupportedOperationException(
       "MathEval internal function setup is incorrect - internal function \""
           + fncnam
           + "\" not handled");
 }