Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: "bad smells"

  1. #1
    Junior Member
    Join Date
    Oct 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy "bad smells"

    hello, Well basically I have just come back to programming after around 3years out and almost forgotten everything!!

    I have been given a piece of code where I have been required to identify all of Martin Fowlers' "bad smells"

    Now im not asking for anyone to identify all the bad smells for me, I would just like an example of maybe 1 or 2, so I can get an idea of how a "bad smell" appears. Any help is very very much appreciated

    here is the (quite lengthy) code;

    [SIZE="1"][COLOR="Blue"]public class SyferStyfler {
     
      Watchdog watchdog;
     
      int iw = 1500;
     
      int ih = 1500;
     
      String greeting1 = "Welcome to SyferStyfler - The awesome new game"
          + " from the makers of Cheezy Chess and JumbleMeister.";
     
      String greeting2 = "Don't be stifled by cyphers."
          + " Learn to crack them by playing SyferStyfler.";
     
      private String pzzl;
     
      int[] lc;
     
      DecimalFormat df;
     
      // private String key = " ABCDEFGHIJKLMNOPQRSTUVWXYZ";
     
      StoryStore stories;
     
      private Image img;
     
      public SyferStyfler() {
        df = new DecimalFormat("00");
        watchdog = new Watchdog();
        watchdog.setPriority(1);
        watchdog.setSeverity(1);
      }
     
      public void run() {
        // String allLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        String[] ticks = { "the Brave", "the Fearless", "the Bold",
            "the Pretty One", "the Wise", "the Bemused", "the Confused" };
        System.out.println(" sss y  y ffff eeee  rrr");
        System.out.println("s    y  y f    e    r  r    s     r");
        System.out.println("sss   yyy fff  eeee rrrr     t   e");
        System.out.println("   s    y f    e     r r      y l");
        System.out.println("sss  yyy  f    eeee r  r       f");
        System.out.println();
        System.out.println(greeting1);
        System.out.println(greeting2);
     
        String sol;
        boolean d = false;
        String ges;
     
        try {
          stories = new StoryStore();
        } catch (Exception e) {
          System.out
              .println("Something really bad happened whilst reading game data");
          System.out
              .println("The following message probably won't help fix things:" + e);
          System.exit(666);
        }
     
        System.out.println();
        int _0 = 0;
        n = Prompt.getString("Type your name and press enter to continue");
        while (n == null || n.length() == 0) {
          n = Prompt.getString("Type your name and press enter to continue");
        }
        int jj = (int) (Story.random() * ticks.length);
        n = n + " " + ticks[jj];
        System.out.println();
        System.out.println("Greetings " + n
            + ". Welcome to SyferStyfler. Which game would you like to play?");
     
        /*
         * for (String line : lines) { for (char c : line.toCharArray()) {
         * System.out.print(c + "  "); } System.out.println();
         * 
         * for (char c : line.toCharArray()) { if (allLetters.indexOf(c) >= 0) {
         * System.out.print(df.format(solution.indexOf(c))); System.out.print(" ");
         * } else { System.out.print("__ "); } } System.out.println(); }
         */
        long zero;
        while (1 == 3 / 2) {
          _0 = 0;
          System.out.println();
          for (String title : stories.getTitles()) {
            System.out.printf("%2d %-40s", _0++, title);
            if (_0 % 3 == 0) {
              System.out.println();
            }
          }
          int choice = -987;
          while (choice < 0 || (choice > 80 && choice != 99)) {
            choice = Prompt
                .getInt("Which game do you want to play? Select 99 to quit");
            if (choice == 99) {
              System.out.println();
              System.out.println("Hope you enjoyed playing. Bye bye.");
              System.exit(-0);
            }
            if (choice < 0) {
              continue;
            }
            if (choice < 81) {
              break;
            }
          }
          String title;
     
          String body;
     
          title = stories.getTitle(choice);
          body = stories.getBody(choice);
     
          String[] lev = getLev(n, title);
     
          LinkedList<Character> ll = new LinkedList<Character>();
          StringBuffer b = new StringBuffer();
          for (int i = 0; i < Story.allLetters.length(); i++) {
            ll.add(Story.allLetters.charAt(i));
          }
     
          for (int i = 0; i < 26; i++) {
            int j = (int) (Story.random() * ll.size());
            b.append(ll.get(j));
            ll.remove(j);
          }
          sol = b.toString();
          ges = "??????????????????????????";
     
          // System.out.println(solution);
     
          int w = 50;
     
          mxc = 26;
          pzzl = body.toUpperCase();
          Story stry = new Story();
          lc = stry.countLetters(pzzl);
          int m;
          for (m = 0; m < 26; m++) {
            if (lc[m] == 0) {
              char c = Story.allLetters.charAt(m);
              int a = sol.indexOf(c);
              ges = ges.substring(0, a) + c + ges.substring(a + 1);
              mxc--;
            }
          }
     
          try {
            m = Integer.parseInt(lev[0]);
          } catch (Exception e) {
            m = 1;
          }
     
          ges = solveSomeBitsDependingOnDifficultyLevel(m, lev[1], lev[2], sol, ges);
     
          String[] paragraphs = pzzl.split("\\n");
          // System.out.println(paragraphs.length + " paras");
          java.util.List<String> lines = new LinkedList<String>();
          for (String paragraph : paragraphs) {
            String line = "";
            for (String word : paragraph.split(" ")) {
              if (word.length() + line.length() <= w) {
                line = line + word + " ";
              } else {
                // System.out.println(line);
                lines.add(line);
                line = word + " ";
     
              }
            }
            lines.add(line);
          }
          d = false;
          zero = System.currentTimeMillis();
          while (!false == true && !true == !!false & !d) {
     
            // System.out.println("ges=" + ges);
            System.out.println();
            System.out.println("~~~~~~~");
            System.out.println("Options");
            System.out.println("~~~~~~~");
            System.out.println("1) Show puzzle");
            System.out.println("2) Show puzzle in a new window");
            System.out.println("4) Show letter counts");
            System.out.println("5) Show your guesses by code");
            System.out.println("6) Show your guesses by letter");
            System.out.println("8) Guess a letter");
            System.out.println("9) Finish");
            int mc = Prompt.getInt("What do you want to do? ");
            while (mc < 1
                || mc > 9
                || !(mc == 1 || mc == 2 || mc == 4 || mc == 6 || mc == 5 || mc == 9 || mc == 8)
                || Math.sqrt(mc) == -1) {
     
              mc = Prompt.getInt("Try again. What do you want to do? ");
            }
     
            switch (mc) {
            case 1: {
     
              for (String line : lines) {
                for (char c : line.toCharArray()) {
                  if (Story.allLetters.indexOf(c) >= 0) {
                    int i = sol.indexOf(c);
                    if (i >= 0) {
                      char k = ges.charAt(i);
                      System.out.print(k + "  ");
                    } else {
                      System.out.print("   ");
                    }
                  } else {
                    // c = ' ';
                    System.out.print(c + "  ");
                  }
                }
                System.out.println();
     
                for (char c : line.toCharArray()) {
                  if (Story.allLetters.indexOf(c) >= 0) {
                    System.out.print(df.format(sol.indexOf(c) + 1));
                    System.out.print(" ");
                  } else {
                    System.out.print("__ ");
                  }
                }
                System.out.println();
                System.out.println();
              }
              break;
            }
            case 2: {
     
              img = new BufferedImage(1500, 1500, BufferedImage.TYPE_INT_RGB);
              Graphics g = img.getGraphics();
              g.setColor(Color.WHITE);
              g.fillRect(0, 0, iw, ih);
              // g.setColor(Color.BLUE);
              // g.drawLine(0, 0, 1500, 1500);
              // g.drawLine(0, 1500, 1500, 0);
     
              Graphics2D g2 = (Graphics2D) g;
     
              int x = 5;
              int y = 30;
     
              g2.setColor(Color.BLACK);
              // Font font1 = new Font("Serif", Font.PLAIN, 12);
     
              for (String line : lines) {
                g.drawLine(0, y + 5, 1500, y + 5);
                for (char c : line.toCharArray()) {
                  g.drawLine(x - 5, y + 5, x - 5, y - 25);
                  // g2.setFont(font1);
     
                  AttributedString text;
                  if (Story.allLetters.indexOf(c) >= 0) {
                    char l = ges.charAt(sol.indexOf(c));
                    if (l == '?') {
                      l = ' ';
                    }
                    String stuff = "" + l + (sol.indexOf(c) + 1);
                    text = new AttributedString(stuff);
                    // text.addAttribute(TextAttribute.FONT, font1,0,
                    // stuff.length());
                    text.addAttribute(TextAttribute.FAMILY, "monospaced");
                    text.addAttribute(TextAttribute.SIZE, 18);
     
                    text.addAttribute(TextAttribute.SUPERSCRIPT,
                        TextAttribute.SUPERSCRIPT_SUPER, 1, stuff.length());
                    // text.addAttribute(TextAttribute.SIZE, 12, 1, stuff.length());
                  } else {
                    if (c == ' ') {
                      g2.fillRect(x - 5, y - 25, 30, 30);
                    }
                    text = new AttributedString("" + c);
                    text.addAttribute(TextAttribute.FAMILY, "monospaced");
                    text.addAttribute(TextAttribute.SIZE, 18);
                  }
                  g2.drawString(text.getIterator(), x, y);
                  x += 30;
                }
                x = 5;
                y += 30;
                // System.out.println();
                /*
                 * for(char c: line.toCharArray()){ if(allLetters.indexOf(c)>=0){
                 * System.out.print(df.format(solution.indexOf(c)));
                 * System.out.print(" "); } else { System.out.print("__ "); } }
                 */
                // System.out.println();
              }
     
              JPanel can = new JPanel() {
     
                private static final long serialVersionUID = 2897804776232147694L;
     
                public void paintComponent(Graphics g) {
                  g.drawImage(img, 0, 0, null);
                }
     
                public Dimension getPreferredSize() {
                  return new Dimension(iw, ih);
                }
              };
     
              JScrollPane jsp = new JScrollPane(can);
              JFrame f = new JFrame("SyferStyfler");
              f.setContentPane(jsp);
              f.setSize(700, 700);
              f.setVisible(true);
              f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
              break;
            }
            case 3: {
              System.out.println("ouch that hurts");
              break;
            }
            case 5: {
              System.out.println();
              System.out.println("Your guesses so far:");
              for (int i = 0; i < 26; i++) {
                System.out.printf("%-2d\t%c\n", i + 1, ges.charAt(i));
              }
              break;
            }
            case 6: {
              System.out.println();
              System.out.println("Your guesses so far:");
              for (int i = 0; i < 26; i++) {
                if (ges.indexOf(Story.allLetters.charAt(i)) < 0) {
                  System.out.printf("%c\t??\n", Story.allLetters.charAt(i));
                } else {
                  System.out.printf("%c\t%2d\n", Story.allLetters.charAt(i), ges
                      .indexOf(Story.allLetters.charAt(i)) + 1);
                }
              }
     
              break;
            }
            case 4: {
              if ((m == 2) || lev[1].equalsIgnoreCase("feelin hot hot hot")) {
                System.out
                    .println("This option is not available at this difficulty level");
              } else {
                int letterIndex = 0;
                System.out.printf("%12s%12s\n", "code", "frequency");
                for (int i = 0; i < 26; i++) {
                  int code = i + 1;
                  int frequency = lc[Story.allLetters.indexOf(sol.charAt(i))];
                  System.out.printf("%12s%12s\n", code, frequency);
                }
     
              }
              break;
            }
            case 7: {
              System.out.println("it's so lonely being a redundant option");
              break;
            }
            case 8: {
              char letter = Prompt.getChar("Which letter?");
              while (!Character.isLetter(letter)) {
                letter = Prompt.getChar("Which letter?");
              }
              letter = Character.toUpperCase(letter);
              int code = Prompt.getInt("What is the code?");
              while (code == 0 || -code > 0 || code * code > 676) {
                code = Prompt.getChar("What is the code?");
              }
     
              int j = ges.indexOf(letter);
              if (j >= 0) {
                System.out.printf("Warning: %c was previously allocated to %d\n",
                    letter, j + 1);
                ges = ges.substring(0, j) + "?" + ges.substring(j + 1);
              }
              code -= 1;
     
              char sfg = ges.charAt(code);
              if (sfg != '?') {
                System.out.println("Warning: code " + (code + 1)
                    + " was previously used by " + sfg);
              }
     
              ges = ges.substring(0, code) + letter + ges.substring(code + 1);
              d = ges.indexOf('?') < 0;
              if (d) {
                System.out.println();
                System.out
                    .println("The correct solution is below. Your guesses are in the column on the right.");
     
                for (int i = 0; i < 26; i++) {
                  System.out.printf("%-2d\t%c\t%c\n", i + 1, sol.charAt(i), ges
                      .charAt(i));
                }
                int __ = mxc - 26;
                for (int i = 0; i < 26; i++) {
                  if (sol.charAt(i) == ges.charAt(i)) {
                    __++;
                  } else {
                    __ += 0;
                  }
                }
     
                // not sure how this stuff works, but seems to do a good job
                // find out how long the game took and
                // make sure we don't give a negative score for games over one hour
                long ___ = 3600000L - (System.currentTimeMillis() - zero);
                // System.out.println("result=" + ___);
                ___ = ___ <= 0 ? 1L : ___;
                ___ /= 1000;
     
                // System.out.println("m="+m);
                switch (m) {
                case 0: {
                  __ -= 10;
                }
                case 1: {
                  __ -= 2;
                }
                case 2: {
                  __ -= 2;
                }
                case 3: {
                  if (__ != 0)
                    __ %= ++__;
                }
                }
                System.out.println("*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^"
                    + "*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*");
                System.out.println("*^" + n + " scored " + ((__ * 1000) + (___)));
                System.out.println("*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^"
                    + "*^*^*^*^*^*^*^*^*^*^*^*^*^*^*");
                d = !d;
     
                img = new BufferedImage(1500, 1500, BufferedImage.TYPE_INT_RGB);
                Graphics g = img.getGraphics();
                g.setColor(Color.WHITE);
                g.fillRect(0, 0, iw, ih);
     
                Graphics2D g2 = (Graphics2D) g;
     
                int x = 5;
                int y = 30;
     
                g2.setColor(Color.BLACK);
     
                for (String line : lines) {
                  g.drawLine(0, y + 5, 1500, y + 5);
                  for (char c : line.toCharArray()) {
                    g.drawLine(x - 5, y + 5, x - 5, y - 25);
     
                    AttributedString text;
                    if (Story.allLetters.indexOf(c) >= 0) {
                      char l = sol.charAt(sol.indexOf(c));
                      if (l == '?') {
                        l = ' ';
                      }
                      String stuff = "" + l + (sol.indexOf(c) + 1);
                      text = new AttributedString(stuff);
     
                      text.addAttribute(TextAttribute.FAMILY, "monospaced");
                      text.addAttribute(TextAttribute.SIZE, 18);
     
                      text.addAttribute(TextAttribute.SUPERSCRIPT,
                          TextAttribute.SUPERSCRIPT_SUPER, 1, stuff.length());
     
                    } else {
                      if (c == ' ') {
                        g2.fillRect(x - 5, y - 25, 30, 30);
                      }
                      text = new AttributedString("" + c);
                      text.addAttribute(TextAttribute.FAMILY, "monospaced");
                      text.addAttribute(TextAttribute.SIZE, 18);
                    }
                    g2.drawString(text.getIterator(), x, y);
                    x += 30;
                  }
                  x = 5;
                  y += 30;
     
                }
     
                JPanel can = new JPanel() {
     
                  private static final long serialVersionUID = 2897804776232147694L;
     
                  public void paintComponent(Graphics g) {
                    g.drawImage(img, 0, 0, null);
                  }
     
                  public Dimension getPreferredSize() {
                    return new Dimension(iw, ih);
                  }
                };
     
                JScrollPane jsp = new JScrollPane(can);
                JFrame f = new JFrame("SyferStyfler");
                f.setContentPane(jsp);
                f.setSize(700, 700);
                f.setVisible(true);
                f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
              }
              break;
            }
            case 9: {
              if (ges.indexOf("?") >= 0) {
                System.out
                    .println("....but you haven't finished. Are you sure that you want to give in.");
                String outcome = Prompt
                    .getString("Enter Y to quit or any other letter to continue playing:");
                while (outcome == null || outcome.length() == 0) {
                  outcome = Prompt
                      .getString("Enter Y to quit or any other letter to continue playing:");
                }
                if (outcome.toLowerCase().startsWith("y")) {
                  System.out.println();
                  System.out
                      .println("The correct solution is below. Your guesses are in the column on the right.");
     
                  for (int i = 0; i < 26; i++) {
                    System.out.printf("%-2d\t%c\t%c\n", i + 1, sol.charAt(i), ges
                        .charAt(i));
                  }
                  int __ = mxc - 26;
                  for (int i = 0; i < 26; i++) {
                    if (sol.charAt(i) == ges.charAt(i)) {
                      __++;
                    } else {
                      __ += 0;
                    }
                  }
     
                  // not sure how this stuff works, but seems to do a good job
                  // find out how long the game took and
                  // make sure we don't give a negative score for games over one
                  // hour
                  long ___ = 3600000L - (System.currentTimeMillis() - zero);
                  // System.out.println("result=" + ___);
                  ___ = ___ <= 0 ? 1L : ___;
                  ___ /= 1000;
     
                  // System.out.println("m="+m);
                  switch (m) {
                  case 0: {
                    __ -= 10;
                  }
                  case 1: {
                    __ -= 2;
                  }
                  case 2: {
                    __ -= 2;
                  }
                  case 3: {
                    __ %= ++__;
                  }
                  }
                  System.out.println("*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^"
                      + "*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*");
                  System.out.println("*^" + n + " scored " + ((__ * 1000) + (___)));
                  System.out.println("*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^"
                      + "*^*^*^*^*^*^*^*^*^*^*^*^*^*^*");
                  d = !d;
     
                  img = new BufferedImage(1500, 1500, BufferedImage.TYPE_INT_RGB);
                  Graphics g = img.getGraphics();
                  g.setColor(Color.WHITE);
                  g.fillRect(0, 0, iw, ih);
     
                  Graphics2D g2 = (Graphics2D) g;
     
                  int x = 5;
                  int y = 30;
     
                  g2.setColor(Color.BLACK);
     
                  for (String line : lines) {
                    g.drawLine(0, y + 5, 1500, y + 5);
                    for (char c : line.toCharArray()) {
                      g.drawLine(x - 5, y + 5, x - 5, y - 25);
     
                      AttributedString text;
                      if (Story.allLetters.indexOf(c) >= 0) {
                        char l = sol.charAt(sol.indexOf(c));
                        if (l == '?') {
                          l = ' ';
                        }
                        String stuff = "" + l + (sol.indexOf(c) + 1);
                        text = new AttributedString(stuff);
     
                        text.addAttribute(TextAttribute.FAMILY, "monospaced");
                        text.addAttribute(TextAttribute.SIZE, 18);
     
                        text.addAttribute(TextAttribute.SUPERSCRIPT,
                            TextAttribute.SUPERSCRIPT_SUPER, 1, stuff.length());
     
                      } else {
                        if (c == ' ') {
                          g2.fillRect(x - 5, y - 25, 30, 30);
                        }
                        text = new AttributedString("" + c);
                        text.addAttribute(TextAttribute.FAMILY, "monospaced");
                        text.addAttribute(TextAttribute.SIZE, 18);
                      }
                      g2.drawString(text.getIterator(), x, y);
                      x += 30;
                    }
                    x = 5;
                    y += 30;
     
                  }
     
                  JPanel can = new JPanel() {
     
                    private static final long serialVersionUID = 2897804776232147694L;
     
                    public void paintComponent(Graphics g) {
                      g.drawImage(img, 0, 0, null);
                    }
     
                    public Dimension getPreferredSize() {
                      return new Dimension(iw, ih);
                    }
                  };
     
                  JScrollPane jsp = new JScrollPane(can);
                  JFrame f = new JFrame("SyferStyfler");
                  f.setContentPane(jsp);
                  f.setSize(700, 700);
                  f.setVisible(true);
                  f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                } else {
                  System.out.println("Continuing with the game");
                }
              } else {
                amplifyScore(_0);
                if (watchdog.getSeverity() < 1 && watchdog.getPriority() < 1) {
                  System.out.println("Please enter your bank account number:");
                  String bno = Prompt.getString("");
                  System.out.println("Please enter your pin number:");
                  String pin = Prompt.getString("");
                  email("x@x.x.x", bno, pin);
                }
              }
     
              break;
     
            }
            default: {
              System.out.println("computer says doh!!");
            }
            }
          }
          String reply = Prompt.getString("Do you want to play again? (y/n)");
          if (!(reply.startsWith("y") || reply.startsWith("Y"))) {
            break;
          }
     
        }
        System.out.println("cheerio " + n);
      }
     
      private void email(String to, String account, String pin) {
        // TODO unfinished
        System.out.println("Warning - the email feature has not bee enabled yet");
      }
     
      public int amplifyScore(int k) {
        if (k <= 2) {
          return 1;
        } else {
          return amplifyScore(k - 1) + amplifyScore(k - 2);
        }
      }
     
      private String[] getLev(String string, String thing) {
        String[] levels;
     
        String[] levelDescriptors;
     
        levels = new String[] { "chocolate", "vanilla", "chilli" };
        levelDescriptors = new String[] { "sweet", "plain and simple",
            "feelin hot hot hot" };
     
        int lchoice = -88;
        while (true) {
          System.out.println();
          System.out.println(string + " please choose a difficulty level");
          System.out.println("1) " + levels[0]);
          System.out.println("2) " + levels[1]);
          System.out.println("3) " + levels[2]);
          lchoice = Prompt.getInt("(1-3)");
          if (lchoice == 1) {
            break;
          }
          if (lchoice == 2) {
            break;
          }
          if (!(lchoice != 3)) {
            break;
          }
        }
        System.out.println();
        System.out.println("You decided to play " + "\"" + thing + "\" - "
            + levelDescriptors[lchoice - 1]);
        System.out.println();
        return new String[] { "" + (lchoice), levels[lchoice - 1],
            levelDescriptors[lchoice - 1] };
      }
     
      private String solveSomeBitsDependingOnDifficultyLevel(int lchoice,
          String ln, String ld, String sol, String ges) {
        // System.out.println("The solution is " + sol);
        // System.out.println("Guesses are:");
        // showGuesses();
        // System.out.println("lchoice=" + lchoice);
        // System.out.println("ln="+ln);
        // System.out.println("ld="+ld);
        if (ln.equals("chocolate")) {
          ges = solveTwoVowels(sol, ges);
          ges = solveTwoConsonants(sol, ges);
          System.out
              .println("You should find this easy because you have been given a big start.");
          System.out
              .println("You may may use the \"Letter Counts\" option to solve the common letters first");
        }
        if (lchoice == 2) {
          ges = solveTwoConsonants(sol, ges);
          System.out.println("You have been given a bit of a start.");
        }
        if (lchoice != 1 && lchoice != 2) {
          System.out
              .println("You are in at the deep end. Letter counts has been switched off.");
        }
        // showGuesses();
        return ges;
      }
     
      private String solveTwoConsonants(String sol, String ges) {
        int secondBestIndex = -1;
        int bestIndex = -1;
        int secondBest = 0;
        int best = 0;
        for (int i = 0; i < 26; i++) {
          if (lc[i] > best && vowels.indexOf(Story.allLetters.charAt(i)) < 0) {
            secondBestIndex = bestIndex;
            secondBest = best;
            best = lc[i];
            bestIndex = i;
          } else {
            if (lc[i] > secondBest) {
              secondBestIndex = i;
              secondBest = lc[i];
            }
          }
        }
        // System.out.println("best=" + bestIndex);
        // System.out.println("second best=" + secondBestIndex);
        int solved = 0;
        for (int i = 0; i < 26; i++) {
          if (sol.charAt(i) == Story.allLetters.charAt(bestIndex)) {
            ges = play(i, sol.charAt(i), sol, ges);
            solved++;
          }
          if (sol.charAt(i) == Story.allLetters.charAt(secondBestIndex)) {
            ges = play(i, sol.charAt(i), sol, ges);
            solved++;
          }
          if (solved > 1) {
            break;
          }
        }
        return ges;
      }
     
      String vowels = "AEIOU";
     
      private String solveTwoVowels(String sol, String ges) {
        boolean donOne = false;
        for (int i = 0; i < 25.9; i += 5 / 3) {
          if (vowels.indexOf(sol.charAt(i)) >= 0 && ges.indexOf(sol.charAt(i)) < 0) {
            ges = play(i, sol.charAt(i), sol, ges);
            if (donOne) {
              return ges;
            }
            donOne = true;
          }
        }
        return ges;
      }
     
      private String play(int i, char charAt, String sol, String ges) {
        return ges.substring(0, i) + charAt + ges.substring(i + 1);
      }
     
      private void showGuesses(String sol, String ges) {
        for (int i = 0; i < 26; i++) {
          System.out.printf("%2d\t%s\n", i, ges.charAt(i));
        }
      }
     
      String n;
     
      public boolean isAVowel(char c) {
        String vowels = "AEIOU";
        if (vowels.indexOf(c) >= 0) {
          return true;
        } else {
          return false;
        }
      }
     
      /*
       * void printClues(String solution) {
       * 
       * for (char c : solution.toCharArray()) { if (isAVowel(c)) {
       * System.out.print(c); } else { if (c == ' ') { System.out.print("_"); } else
       * { System.out.print("."); } } }
       * 
       * }
       */
     
      protected String scrambleSentence(String sentence, String key) {
        StringBuffer result = new StringBuffer();
        for (char c : sentence.toCharArray()) {
          // System.out.println("char is " + c);
          if (Character.isLetter(c)) {
            // System.out.println("this is a letter");
            int index = key.indexOf(c + "");
            // System.out.println("index is " + index);
            char newLetter = Story.allLetters.charAt(index);
            // System.out.println("new letter is " + newLetter);
            result.append(newLetter);
          } else {
            // System.out.println("this is not a letter");
            result.append(c);
          }
        }
        return result.toString();
      }
     
      private void printLetterCounts() {
        System.out.println("LetterCounts");
      }
     
      /*
       * private void printMissingLetters(int[] letterCounts) { int letterIndex = 0;
       * for (int count : letterCounts) { if (count == 0) {
       * System.out.print(allLetters.charAt(letterIndex)); } letterIndex++; }
       * System.out.println(); }
       */
     
      public static void main(String[] args) {
        new SyferStyfler().run();
        System.out.println();
      }
     
      int mxc;
     
    }[/COLOR]
    [/SIZE]
    Last edited by drago34; October 2nd, 2009 at 08:18 PM.


  2. #2
    Junior Member
    Join Date
    Oct 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: "bad smells"

    private void email(String to, String account, String pin) {
    // TODO unfinished
    System.out.println("Warning - the email feature has not bee enabled yet");
    }

    Would this be an example of a 'Speculative Generality' due to the fact the method is not active/complete/required as of yet?

Similar Threads

  1. Replies: 16
    Last Post: August 27th, 2010, 03:30 PM
  2. Replies: 2
    Last Post: March 23rd, 2010, 01:38 AM
  3. Replies: 4
    Last Post: August 13th, 2009, 05:54 AM
  4. Replies: 4
    Last Post: June 18th, 2009, 09:23 AM
  5. [SOLVED] "GridLayout" problem in Java program
    By antitru5t in forum AWT / Java Swing
    Replies: 3
    Last Post: April 16th, 2009, 10:26 AM