Question

Write a Java application with a JavaFX GUI that takes a String input by the user...

Write a Java application with a JavaFX GUI 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.

Homework Answers

Answer #1

Hi. I have answered this question before. 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*/


Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a Java application a String input by the user and shows whether the string contains...
Write a Java application 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. needs, at minimum, asl user to input for the String, then...
Write a java program that repeatedly prompts the user to input a string starting with letters...
Write a java program that repeatedly prompts the user to input a string starting with letters from the English alphabet. The program must stop getting input when the user inputs the string “STOOOOP”. Then the program must display the words starting with each letter from the alphabet in a separate line (e.g. you need to make a new line after all words starting with a specific letter are finished.
3. Write function, leastChar(inputString) that takes as input a string of one or more letters (and...
3. Write function, leastChar(inputString) that takes as input a string of one or more letters (and no other characters) and prints 1) the "least" character in the string, where one character is less than another if it occurs earlier in the alphabet (thus 'a' is less than 'C' and both are less than 'y') and 2) the index of the first occurrence of that character. When comparing letters in this problem, ignore case - i.e. 'e' and 'E' should be...
Write a cencrypt() function that takes a arbitrary length string and an integer as inputs and...
Write a cencrypt() function that takes a arbitrary length string and an integer as inputs and returns a string as output. The cencrypt() function you write in lab today needs to work on strings that contain upper-case letters, lower-case letters, or both. The output string should be all upper-case letters. (The Romans of Caesar's time used only what today we call upper-case letters.) So a call to cencrypt("Caesar", 1) should return (return not print) the string “DBFTBS” and a call...
Write a recursive method that takes as input a string s and returns a list containing...
Write a recursive method that takes as input a string s and returns a list containing all the anagrams of the string s. An anagram is a word formed by rearranging the letters of a different word. For example, the word ‘binary’ is an anagram of ‘brainy’. Note that the output list should not contain duplicates. Java
Write a Java program that prompts the user to input a word (String). The program must...
Write a Java program that prompts the user to input a word (String). The program must print the reversed word with all consecutive duplicate characters removed. The program must contain the following classes: - The StackX class (you can use the Java Stack class). - The Reverse class which must contain a private data field called “word” of type string, a constructor, and a void method called revNoDup(). The revNoDup() method must reverse the word and remove the consecutive duplicate...
Create a function in MIPS using MARS to determine whether a user input string is a...
Create a function in MIPS using MARS to determine whether a user input string is a palindrome or not. Assume that the function is not part of the same program that is calling it. This means it would not have access to your .data segment in the function, so you need to send and receive information from the function itself. The program should be as simple as possible while still using necessary procedures. Follow the instructions below carefully. Instructions: ●...
Objective: Write a Java program that will use a JComboBox from which the user will select...
Objective: Write a Java program that will use a JComboBox from which the user will select to convert a temperature from either Celsius to Fahrenheit, or Fahrenheit to Celsius. The user will enter a temperature in a text field from which the conversion calculation will be made. The converted temperature will be displayed in an uneditable text field with an appropriate label. Specifications Structure your file name and class name on the following pattern: The first three letters of your...
Part 1 Write a program that reads a line of input and display the characters between...
Part 1 Write a program that reads a line of input and display the characters between the first two '*' characters. If no two '*' occur, the program should display a message about not finding two * characters. For example, if the user enters: 1abc*D2Efg_#!*345Higkl*mn+op*qr the program should display the following: D2Efg_#! 1) Name your program stars.c. 2) Assume input is no more than 1000 characters. 3) String library functions are NOT allowed in this program. 4) To read a...
JAVA ASSIGNMENT 1. Write program that opens the file and process its contents. Each lines in...
JAVA ASSIGNMENT 1. Write program that opens the file and process its contents. Each lines in the file contains seven numbers,which are the sales number for one week. The numbers are separated by comma.The following line is an example from the file 2541.36,2965.88,1965.32,1845.23,7021.11,9652.74,1469.36. The program should display the following: . The total sales for each week . The average daily sales for each week . The total sales for all of the weeks .The average weekly sales .The week number...