To use GUI tools for input and output windows, you should use an Input Dialog an
ID: 667354 • Letter: T
Question
To use GUI tools for input and output windows, you should use an Input Dialog and Message Dialog of JOptionPane.
Please do not use a standard Java application, and resubmit with a GUI Java application.
here is my code i am so confussed. thanks in advance.
import java.io.*;
import java.util.*;
// Class to find the acronym of given words
public class ThreeLetterAcronym
{
// Main method
public static void main(String[] arg)
{
// Declare the required variables
String in_word = "";
String ac_acro = "";
int pos;
// Scanner to read the input
Scanner in = new Scanner ( System.in );
System.out.println("Please enter your 3 words");
// Code to read input
in_word = in.nextLine();
int count = 1;
pos = 0;
//Code to take first letter of word and convert it into upper case
ac_acro += Character.toUpperCase(in_word.charAt(pos));
while(pos < in_word.length())
{
// Code to check the string have blank space and count is less than 3
if(in_word.charAt(pos) == ' ' && count < 3)
{
count++;
//Code to take first letter of word and convert it into upper case
ac_acro += Character.toUpperCase(in_word.charAt(pos + 1));
}
++pos;
}
// Code to print the acronym
System.out.println("The acronym of given word is " +ac_acro);
}
}
public class Acronym {
public static void main(String[] args) {
String phrase = JOptionPane.showInputDialog(null,
"Please enter three words.");
String[] word = phrase.split(" ");
String acronym =
Character.toString(word[0].charAt(0)).toUpperCase() +
Character.toString(word[1].charAt(0)).toUpperCase() +
Character.toString(word[2].charAt(0)).toUpperCase();
JOptionPane.showMessageDialog(null, "Original words were: " +phrase + " Three letter acronym is " + acronym);
}}
here is also the main directions
Three-letter acronyms are common in the business world. For example, in Java you use the IDE (Integrated Development Environment) in the JDK (Java Development Kit) to write programs used by the JVM (Java Virtual Machine) that you might send over a LAN (local area network). Programmers even use the acronym TLA to stand for three-letter acronym. Write a program that allows a user to enter three words, and display the appropriate three-letter acronym in all uppercase letters. If the user enters more than three words, ignore the extra words. Figure 7-22 shows a typical execution. Save the file as ThreeLetterAcronym.java.
Typical execution of the ThreeLetterAcronym program
Explanation / Answer
import java.io.*;
import java.util.*;
public class Acronym {
public static void main(String[] args) {
String phrase = JOptionPane.showInputDialog(null,"Please enter three words.");
String[] word = phrase.split(" ");
if (word.length != 3)
JOptionPane.showMessageDialog(null, "Only 3 letter are allowed to enter");
String acronym = Character.toString(word[0].charAt(0)).toUpperCase() + Character.toString(word[1].charAt(0)).toUpperCase() + Character.toString(word[2].charAt(0)).toUpperCase();
JOptionPane.showMessageDialog(null, "Original words were: " +phrase + " Three letter acronym is " + acronym);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.