Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /******************************************************************************
- Welcome to GDB Online.
- GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
- C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
- Code, Compile, Run and Debug online from anywhere in world. First thing we need is random text.
- Jumble is a word puzzle with a clue, a drawing illustration the clue, and a set of words, each of which is jumped by
- scrabling its letters. A solver reconstructs the words, and then arranges letters at marked positions in the words to
- spell the answer phrase to the clue. The clue and illustration always provide hints about the answer phrase. The answer
- phrase frequently uses a homophone or a pun. Jumpbe was created in 1954 by Martin naydel, who is better known for his work
- on comic books. It originally appeared under the title Scramble. Henri Arnold and Bob Lee took over the feature in 1962 and
- 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
- valuable properties of its distributor, US company Tribune
- *******************************************************************************/
- import java.util.*;
- import java.util.regex.*;
- import java.awt.*;
- import javax.swing.*;
- public class Main
- {
- private String jumble;
- public static void main(String[] args) {
- Main m = new Main();
- String txt = "Jumble is a word puzzle with a clue, a drawing illustrating the clue, and a set of words, each of which is " +
- "jumbled by scrambling its letters. A solver reconstructs the words, and then arranges letters at marked positions in the " +
- "words to spell the answer phrase to the clue. The clue and illustration always provide hints about the answer phrase. The " +
- "answer phrase frequently uses a homophone or pun.Jumble was created in 1954 by Martin Naydel, who is better known for " +
- "his work on comic books. It originally appeared under the title Scramble. Henri Arnold and Bob Lee took over the " +
- "feature in 1962 and continued for at least 30 years. As of 2013, Jumble is created by David L. Hoyt and Jeff Knurek. " +
- "Jumble is one of the most valuable properties of its distributor, US company Tribune Content Agency, which owns the " +
- "JUMBLE trademarks and copyrights. Daily and Sunday Jumble puzzles appear in over 600 newspapers in the United States and " +
- "internationally. The current syndicated version found in most daily newspapers (under the official title Jumble, That " +
- "Scrambled Word Game) has four base anagrams, two of five letters and two of six, followed by a clue and a series of blank " +
- "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 " +
- "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 " +
- "the given clue, the player must unscramble all four of the scrambled words; the letters that are in the clue will be " +
- "circled. The contestant then unscrambles the circled letters to form the answer to the clue. An alternate workaround is " +
- "to solve some of the scrambled words, figure out the answer to the clue without all the letters, then use the textra " +
- "letters as aids to solve the remaining scrambled words.There are many variations of puzzles from the Jumble brand including " +
- "Jumble, Jumble for Kids, Jumble Crosswords, TV Jumble, Jumble BrainBusters, Jumble BrainBusters Junior, Hollywood Jumble, " +
- "Jumble Jong, Jumble Word Vault, Jumpin' Jumble, Jumble Solitaire, and Jumble Word Web.";
- String[] words = txt.split(" ");
- ArrayList<String> wordlist = new ArrayList<String>(Arrays.asList(words));
- HashSet<String> filtered = new HashSet<String>();
- wordlist.stream()
- .filter(e -> m.tester(e))
- .map(e -> e.toLowerCase())
- .forEach(e -> filtered.add(e));
- ArrayList<String> thewords = new ArrayList <String>(filtered);
- Random r = new Random();
- String randomword = thewords.get(r.nextInt(thewords.size()));
- //System.out.println(thewords.get(r.nextInt(thewords.size())));
- //for (String s : thewords){
- //System.out.println(s);
- //}
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- m.setupWindow();
- }
- });
- m.jumble = m.scrambleletters(randomword);
- System.out.println("Solve this jumble: " + m.jumble);
- Scanner guess = new Scanner(System.in);
- String guessed = guess.nextLine();
- if(randomword.compareTo(guessed) == 0){
- System.out.println("You won!");
- }
- else{
- System.out.println("This is the correct word: " + randomword);
- }
- guess.close();
- }
- public boolean tester(String S){
- Pattern P = Pattern.compile( "[.,123456789();'0!?-]" );
- Matcher m = P.matcher(S);
- if (m.find()) {
- return false;
- }
- if (S.length() < 5){
- return false;
- }
- return true;
- }
- public String scrambleletters(String S){
- ArrayList<Character> scrambled = new ArrayList<Character>();
- for(char c : S.toCharArray()){
- scrambled.add(c);
- }
- StringBuilder scrambledletters = new StringBuilder();
- int len = scrambled.size();
- int l;
- Random r = new Random();
- for(int i = 0; i < len; i++){
- l = scrambled.size();
- int idx = r.nextInt(l);
- scrambledletters.append(scrambled.remove(idx));
- }
- return scrambledletters.toString();
- }
- public void setupWindow(){
- JFrame frame = new JFrame( "Jumble Game" );
- JLabel label = new JLabel( jumble );
- JTextField yourguess = new JTextField( "Enter your guess" );
- JButton button = new JButton( "Submit" );
- JButton button1 = new JButton( "New Word" );
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- Container contentpane = frame.getContentPane();
- contentpane.add(button1);
- button1.setBounds( 10, 10, 200, 100);
- contentpane.add(button);
- button.setBounds( 110, 110, 100, 50);
- contentpane.add(yourguess);
- yourguess.setBounds( 100, 200, 100, 50);
- contentpane.add(label);
- label.setBounds( 200, 200, 100, 50);
- contentpane.setLayout( null );
- frame.setVisible( true );
- frame.setSize(400,400);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement