Question

In: Computer Science

Write a Java application with a JavaFXGUI that takes a String input by the user and...

Write a Java application with a JavaFXGUI that takes a String input by the user and shows whether the string contains all 26 letters of the (English version of the Latin) alphabet. For example, "Pack my box with five dozen liquor jugs" contains all 26 letters, but "The quick frown box jumps over the hazy log" does not contain a d. It does not matter whether one or more letters appear more than once.

The GUI needs, at minimum, a label to say "Enter String: ", a TextBox to take input for the String, a label to show the answer ("String contains all 26 letters" or "String does not contain all 26 letters", and a button to trigger the method to determine the outcome.

Hints:

  • Use toLowerCase() or toUpperCase() on the characters from the String so that you do not have to worry about case.
  • *Absolutely don't* write 26 different statements to test all 26 letters. You can use a loop and cast (int) the loop counter to a char; upper case A is Unicode character 65.
  • String has a contains() method much like the one in List.

Solutions

Expert Solution

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks

// CheckLetters.java

import javafx.application.Application;

import static javafx.application.Application.launch;

import javafx.geometry.Insets;

import javafx.scene.Scene;

import javafx.scene.control.Button;

import javafx.scene.control.Label;

import javafx.scene.control.TextField;

import javafx.scene.layout.GridPane;

import javafx.stage.Stage;

public class CheckLetters extends Application {

    //declaring important UI components

    TextField input;

    Label output;

    @Override

    public void start(Stage primaryStage) {

        //initializing all UI components

        Label lbl1 = new Label("Enter String: ");

        input = new TextField();

        //setting pref width of input text field to maximum so that the text field

        //will be stretched according to screen size

        input.setPrefWidth(Double.MAX_VALUE);

        output = new Label("");

        Button check = new Button("Check");

        //enabling check button to call the check method (defined below) upon click

        check.setOnAction(e -> check());

       

        //creating a GridPane, adjusting padding & spacing

        GridPane root = new GridPane();

        root.setPadding(new Insets(20));

        root.setVgap(20);

        root.setHgap(20);

       

        //adding all components to pane

        root.add(lbl1, 0, 0); //lbl1 to column 0, row 0

        root.add(input, 1, 0, 2, 1); //input to col 1, row 0, column span 2, row span 1

        root.add(output, 0, 1, 2, 1);

        root.add(check, 0, 2);

       

        //setting up & displaying a scene

        Scene scene = new Scene(root, 600, 200);

        primaryStage.setScene(scene);

        primaryStage.setTitle("Check Letters");

        primaryStage.show();

    }

   

    //handler method

    private void check() {

        //getting text, converting to lower case

        String text = input.getText().toLowerCase();

        //initially assuming text contain all 26 letters

        boolean allLettersFound = true;

        //looping from a to z

        for (char c = 'a'; c <= 'z'; c++) {

            //if text does not contain c, setting allLettersFound to false

            if (!text.contains("" + c)) {

                allLettersFound = false;

                break;

            }

        }

        //at the end, displaying the result based on the value of allLettersFound

        if (allLettersFound) {

            output.setText("String contains all 26 letters");

        } else {

            output.setText("String does not contain all 26 letters");

        }

    }

    public static void main(String[] args) {

        launch(args);

    }

}

/*OUTPUT*/



Related Solutions

Write a Java application with a JavaFXGUI that takes a String input by the user and...
Write a Java application with a JavaFXGUI that takes a String input by the user and shows whether the string contains all 26 letters of the (English version of the Latin) alphabet. For example, "Pack my box with five dozen liquor jugs" contains all 26 letters, but "The quick frown box jumps over the hazy log" does not contain a d. It does not matter whether one or more letters appear more than once. The GUI needs, at minimum, a...
Java Code: Write an application that takes in user input. (Name, Age, and Salary) ------ Write...
Java Code: Write an application that takes in user input. (Name, Age, and Salary) ------ Write an application that includes a constructor, user input, and operators.
Write a program that takes a string input from the user and then outputs the first...
Write a program that takes a string input from the user and then outputs the first character, then the first two, then the first three, etc until it prints the entire word. After going up to the full word, go back down to a single letter. LastNameUpDown. Input: Kean Output: K Ke Kea Kean Kea Ke K
Write a Java method that takes an array of char and a String as input parameters...
Write a Java method that takes an array of char and a String as input parameters and and returns an boolean. The method returns true if we can find the input string inside the array by starting at any position of the array and reading either forwards or backwards.
Write a Java program that prompts the user to input a string and prints whether it...
Write a Java program that prompts the user to input a string and prints whether it is a palindrome. A palindrome is a string which reads the same backward as forward, such as Madam (disregarding punctuation and the distinction between uppercase and lowercase letters). The program must use the stack data structure. The program must include the following classes: The StackX class (or you can use the Java Stack class). The Palindrome class which must contain a method named palindrome()...
Python Program 1: Write a program that takes user input in the form of a string...
Python Program 1: Write a program that takes user input in the form of a string Break up the string into a list of characters Store the characters in a dictionary The key of the dictionary is the character The value of the dictionary is the count of times the letter appears Hint: remember to initialize each key before using Output of program is the count of each character/letter Sort the output by key (which is the character) Python Program...
Write a recursive method using Java that takes a string s as input and returns a...
Write a recursive method using Java that takes a string s as input and returns a list that contains all the anagrams of the string s. An anagram is a word formed by rearranging the letters of a different word. For instance, the word ‘cat’ is an anagram of ‘act’. Notice that the output list cannot contain duplicates.
Write a Java method that takes an input string and computes the income minus the expenses....
Write a Java method that takes an input string and computes the income minus the expenses. The income components are indicated by numbers; while the expenses from your spending are numbers starting with a minus sign '-'. The input string may contain lowercase and uppercase letters, as well as other characters. Note that Character.isDigit(char) tests if a char is one of the chars '0', '1', ..., '9'. Also recall that Integer.parseInt(string) converts a string to an int. Test cases :...
Write a Java program which takes a String representing an arithmetic expression as an input and...
Write a Java program which takes a String representing an arithmetic expression as an input and displays whether or not the expression is balanced. If the expression is not balanced (i.e. the wrong # of parentheses or in the wrong order) it will display an error message. For Example: Input an expression: ( ( 2 + 4 ) * 2 ) Expression is balanced Input an expression: ( 5 * 7 – 6 ) ) Error: Expression is not balanced.......
Write a Java application that checks a string for correct parenthesization. The input comes from the...
Write a Java application that checks a string for correct parenthesization. The input comes from the keyboard and should (but might not) consist solely of the delmiters (, ), [, ], {, and } separated by whitespace. The output of the program must include following: OK Opener/closer mismatch Missing closer Missing opener Unexpected symbol The name of your class should be ParenChecker. For example, if the input was: ( [ { } ] ) the program should produce the following...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT