My java program currently takes in a phrase from user input and asks the user to
ID: 3631406 • Letter: M
Question
My java program currently takes in a phrase from user input and asks the user to replace a certain word within the phrase to be replaced with another word. After that it outputs the same phrase except with the changed sentence. I'd like this output to be all capitalized. Here is my codeimport javax.swing.*;
public class Replacer
{
public static void main(String args[])
{
JFrame frame = new JFrame();
String originalWord;
String replacedWord;
int response;
do
{
originalWord = JOptionPane.showInputDialog("The Line of Text to be changed is:");
String replacingWord = JOptionPane.showInputDialog("Which word from the sentence do you want changed?");
String replaceAs = JOptionPane.showInputDialog("Replace that word with?");
replacedWord=originalWord;
replacedWord = replacedWord.replaceAll(replacingWord,replaceAs);
JOptionPane.showMessageDialog(frame,"The line of text to be changed is: "+originalWord);
JOptionPane.showMessageDialog(frame,"That line has been rephrased to read: "+replacedWord);
response = JOptionPane.showConfirmDialog(null, "Do you want to continue?", "Confirm",
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
}
while(response==JOptionPane.YES_OPTION);
JOptionPane.showMessageDialog(frame,"Goodbye!");
}
}
//end program
The line that has this code:
JOptionPane.showMessageDialog(frame,"That line has been rephrased to read: "+replacedWord);
is the output. How can i change something in the program to have the output all capital? (it does not have to be this specific line, but if its possible to just change this line, then please change it)
Explanation / Answer
//Do this
import javax.swing.*;
public class Replacer{
public static void main(String args[]){
JFrame frame = new JFrame();
String originalWord;
String replacedWord;
int response;
do{
originalWord = JOptionPane.showInputDialog("The Line of Text to be changed is:");
String replacingWord = JOptionPane.showInputDialog("Which word from the sentence do you want changed?");
String replaceAs = JOptionPane.showInputDialog("Replace that word with?");
replacedWord = originalWord;
replacedWord = replacedWord.replaceAll(replacingWord,replaceAs);
JOptionPane.showMessageDialog(frame,"The line of text to be changed is: "+originalWord);
JOptionPane.showMessageDialog(frame,"That line has been rephrased to read: "+ replacedWord.toUpperCase());
response = JOptionPane.showConfirmDialog(null, "Do you want to continue?", "Confirm",
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
}
while(response==JOptionPane.YES_OPTION);
JOptionPane.showMessageDialog(frame,"Goodbye!");
}
}
//end program
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.