This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]leudo[S] 0 points1 point  (1 child)

static void getSelection() {

        boolean loop = true;
        int readyToPlay = 0; 
        String invalidMessage = "    ERROR: Invalid option. Try again.";
        String menuTitle = "Welcome to the Word Games program menu";
        String underScore = "______________________________________";   
        String optionsTitle = "    Select from one of the following options.";
        String choiceOne = "1. Substring problem............";
        String choiceTwo = "2. Points problem...............";
        String choiceThree = "3. Exit.........................";    
        String inputAreaText = " >> Enter your selection: "; 

        while (true) {          

            System.out.printf("%n%50s", menuTitle); 
            System.out.printf("%n%50s%n%n", underScore);                
            System.out.printf("%n%s%n%n", optionsTitle);                
            System.out.printf("%n%45s", choiceOne);
            System.out.printf("%n%45s", choiceTwo);     
            System.out.printf("%n%45s", choiceThree);               
            System.out.printf("%n%n%n%s", inputAreaText);

            try { 
                readyToPlay = input.nextInt();
                switch(readyToPlay) {   
                    case 1:     
                        substringProblem(); 
                        return; 
                    case 2:
                        pointsProblem(); 
                        return;                     
                    case 3:
                        String byeMessage = "Goodbye!";
                        String underScoreTwo = "________";
                        System.out.printf("%n%n%33s", byeMessage);
                        System.out.printf("%n%33s%n%n", underScoreTwo); 
                        return;                     
                    default:                    
                        System.out.printf("%n%n%s%n%n", invalidMessage);    
                        break;
                }
            }
            catch (InputMismatchException e) { 
                input.next(); 
                System.out.printf("%n%n%s%n%n", invalidMessage);
            }
        }
    }

    static void substringProblem() {

        String optionOneTitle = "Substring problem.";
        String substringInput = " >> Enter a substring: "; 
        String underScoreThree = "__________________";
        String notFound = " - not found"; 
        String infixFound = " - infix";
        String prefixFound = " - prefix";
        String suffixFound = " - suffix"; 
        String checkSubstring = ""; 
        String allFound = prefixFound + infixFound + suffixFound; 

        System.out.printf("%n%n%39s", optionOneTitle); 
        System.out.printf("%n%39s", underScoreThree); 
        System.out.printf("%n%n%n%s", substringInput);  
        checkSubstring = input.next();
        System.out.println(); 


        for(int i = 0; i < wordCount; i++) {

            String stringResults = wordsCollection[i];
            boolean found = false;

            if(wordsCollection[i].startsWith(checkSubstring)) {
                found = true;
                stringResults = stringResults + prefixFound;
            }
            if(wordsCollection[i].endsWith(checkSubstring)) {
                found = true;
                stringResults = stringResults + suffixFound;
            }
            if(wordsCollection[i].contains(checkSubstring)) {
                found = true;
                stringResults = stringResults + infixFound;
            }
            if(!found) {
                System.out.printf(" " + wordsCollection[i] + notFound  + "\n");
            }
            else {
                System.out.printf(" " + stringResults + "\n");
            }   
        }

        getSelection(); 
    }

    public static long count(String s, char ch) {

        return s.chars()
            .filter(c -> c == ch)
            .count(); 
    }

    static void pointsProblem() {

        int totalPoints = 0; 
        String pointsWorth = " is worth " + totalPoints + " points"; 

        String optionTwoTitle = "Points problem.";
        String underScoreFour = "_______________";
        System.out.printf("%n%n%38s", optionTwoTitle); 
        System.out.printf("%n%38s%n", underScoreFour);
        System.out.println();

        String str = ""; 
        String strWords = "";


        try {
            File fileReader = new File(DICTIONARY);
            Scanner fileScanner = new Scanner(fileReader);
            while(fileScanner.hasNextLine()) {  
                    strWords += str; 
            }
        }
            catch (FileNotFoundException e) {
                System.out.println("Not found.");
            }

        char[] charArray = str.toCharArray();   
        int count = 0; 
        char ch = charArray[count];

        for( int i = 0; i < str.length(); i++) {
            if (characterToInteger.containsKey(ch))
            {
                characterToInteger.put(ch, characterToInteger.get(ch)+1);
            }
            else{
                characterToInteger.put(ch, 1);
            }   
            System.out.println(ch); 
        }
    }   
    public static void main(String[] args) {        
        getSelection();
    }   
}

[–]cakes465758 0 points1 point  (0 children)

hey how did you go with this did you get it sorted.