Advertisement
Guest User

java jumble updated

a guest
Nov 17th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.45 KB | None | 0 0
  1. /******************************************************************************
  2.  
  3. Welcome to GDB Online.
  4. GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
  5. C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
  6. Code, Compile, Run and Debug online from anywhere in world. First thing we need is random text.
  7. Jumble is a word puzzle with a clue, a drawing illustration the clue, and a set of words, each of which is jumped by
  8. scrabling its letters. A solver reconstructs the words, and then arranges letters at marked positions in the words to
  9. spell the answer phrase to the clue. The clue and illustration always provide hints about the answer phrase. The answer
  10. phrase frequently uses a homophone or a pun. Jumpbe was created in 1954 by Martin naydel, who is better known for his work
  11. on comic books. It originally appeared under the title Scramble. Henri Arnold and Bob Lee took over the feature in 1962 and
  12. continued for at least 30 years. As of 2013, Jumble is created by David L. Hoyt and Jeff Knurek. Jumpbe is one of the most
  13. valuable properties of its distributor, US company Tribune
  14.  
  15. *******************************************************************************/
  16. import java.util.*;
  17. import java.util.regex.*;
  18. import java.awt.*;
  19. import javax.swing.*;
  20.  
  21. public class Main
  22.  
  23. {
  24. private String jumble;
  25. public static void main(String[] args) {
  26. Main m = new Main();
  27. String txt = "Jumble is a word puzzle with a clue, a drawing illustrating the clue, and a set of words, each of which is " +
  28. "jumbled by scrambling its letters. A solver reconstructs the words, and then arranges letters at marked positions in the " +
  29. "words to spell the answer phrase to the clue. The clue and illustration always provide hints about the answer phrase. The " +
  30. "answer phrase frequently uses a homophone or pun.Jumble was created in 1954 by Martin Naydel, who is better known for " +
  31. "his work on comic books. It originally appeared under the title Scramble. Henri Arnold and Bob Lee took over the " +
  32. "feature in 1962 and continued for at least 30 years. As of 2013, Jumble is created by David L. Hoyt and Jeff Knurek. " +
  33. "Jumble is one of the most valuable properties of its distributor, US company Tribune Content Agency, which owns the " +
  34. "JUMBLE trademarks and copyrights. Daily and Sunday Jumble puzzles appear in over 600 newspapers in the United States and " +
  35. "internationally. The current syndicated version found in most daily newspapers (under the official title Jumble, That " +
  36. "Scrambled Word Game) has four base anagrams, two of five letters and two of six, followed by a clue and a series of blank " +
  37. "spaces in which the answer to the clue fits. The answer to the clue is generally a pun of some sort. A weekly kids version " +
  38. "of the puzzle features a 3-letter word plus three 4-letter words. In order to find the letters that are in the answer to " +
  39. "the given clue, the player must unscramble all four of the scrambled words; the letters that are in the clue will be " +
  40. "circled. The contestant then unscrambles the circled letters to form the answer to the clue. An alternate workaround is " +
  41. "to solve some of the scrambled words, figure out the answer to the clue without all the letters, then use the textra " +
  42. "letters as aids to solve the remaining scrambled words.There are many variations of puzzles from the Jumble brand including " +
  43. "Jumble, Jumble for Kids, Jumble Crosswords, TV Jumble, Jumble BrainBusters, Jumble BrainBusters Junior, Hollywood Jumble, " +
  44. "Jumble Jong, Jumble Word Vault, Jumpin' Jumble, Jumble Solitaire, and Jumble Word Web.";
  45. String[] words = txt.split(" ");
  46. ArrayList<String> wordlist = new ArrayList<String>(Arrays.asList(words));
  47. HashSet<String> filtered = new HashSet<String>();
  48. wordlist.stream()
  49. .filter(e -> m.tester(e))
  50. .map(e -> e.toLowerCase())
  51. .forEach(e -> filtered.add(e));
  52. ArrayList<String> thewords = new ArrayList <String>(filtered);
  53. Random r = new Random();
  54. String randomword = thewords.get(r.nextInt(thewords.size()));
  55. //System.out.println(thewords.get(r.nextInt(thewords.size())));
  56. //for (String s : thewords){
  57. //System.out.println(s);
  58.  
  59. //}
  60. EventQueue.invokeLater(new Runnable() {
  61. public void run() {
  62. m.setupWindow();
  63. }
  64. });
  65. m.jumble = m.scrambleletters(randomword);
  66. System.out.println("Solve this jumble: " + m.jumble);
  67. Scanner guess = new Scanner(System.in);
  68. String guessed = guess.nextLine();
  69. if(randomword.compareTo(guessed) == 0){
  70. System.out.println("You won!");
  71. }
  72. else{
  73. System.out.println("This is the correct word: " + randomword);
  74. }
  75. guess.close();
  76. }
  77. public boolean tester(String S){
  78. Pattern P = Pattern.compile( "[.,123456789();'0!?-]" );
  79. Matcher m = P.matcher(S);
  80. if (m.find()) {
  81. return false;
  82. }
  83. if (S.length() < 5){
  84. return false;
  85. }
  86. return true;
  87. }
  88. public String scrambleletters(String S){
  89. ArrayList<Character> scrambled = new ArrayList<Character>();
  90. for(char c : S.toCharArray()){
  91. scrambled.add(c);
  92. }
  93. StringBuilder scrambledletters = new StringBuilder();
  94. int len = scrambled.size();
  95. int l;
  96. Random r = new Random();
  97. for(int i = 0; i < len; i++){
  98. l = scrambled.size();
  99. int idx = r.nextInt(l);
  100. scrambledletters.append(scrambled.remove(idx));
  101. }
  102. return scrambledletters.toString();
  103. }
  104. public void setupWindow(){
  105. JFrame frame = new JFrame( "Jumble Game" );
  106. JLabel label = new JLabel( jumble );
  107. JTextField yourguess = new JTextField( "Enter your guess" );
  108. JButton button = new JButton( "Submit" );
  109. JButton button1 = new JButton( "New Word" );
  110. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  111.  
  112. Container contentpane = frame.getContentPane();
  113. contentpane.add(button1);
  114. button1.setBounds( 10, 10, 200, 100);
  115. contentpane.add(button);
  116. button.setBounds( 110, 110, 100, 50);
  117. contentpane.add(yourguess);
  118. yourguess.setBounds( 100, 200, 100, 50);
  119. contentpane.add(label);
  120. label.setBounds( 200, 200, 100, 50);
  121.  
  122. contentpane.setLayout( null );
  123. frame.setVisible( true );
  124. frame.setSize(400,400);
  125. }
  126.  
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement