Ask your own question, for FREE!
Computer Science 48 Online
xjezzer:

Create a Java application that prompts the user for a word and then outputs the word in uppercase and the length of the word to the user. Create a loop which continues to prompt the user for a word until he or she chooses to quit (i.e. enters Q to quit).

xjezzer:

xjezzer:

output example^^ programming language java

Vocaloid:

@SmokeyBrown when you get a chance

SmokeyBrown:

I'm going to try coding out an example on repl.it, and I'll link it here along with some instructions when I've gotten some progress. Just a moment!

SmokeyBrown:

I go through the process in some detail in the comments of the code. Essentially: you use the Scanner object to take input from the user; you can use a while loop around the main body of code to allow the user to keep running the program until they input "Q" for quit; you can use the .toUpperCase() method for Strings to convert the input to uppercase; you can use the .length() method for Strings to find the number of characters in the input; you can use System.out.println() with "+" symbols and the variables you've stored to print the final output I've provided one possible way for you to put that all that together; feel free to make tweaks and adjustments as you need. Please DO NOT simply copy and paste the code I have written, this will be a disservice to yourself and your learning experience. (in fact, I might take some parts out of the code to make it incomplete so you will not be able to do this) And, again, let me know if there is anything I can help with or any questions you have.

SmokeyBrown:

I have a template that you can work off of here, if you'd like to use that. However, you CANNOT copy-paste the code, since I've replaced some key components with "_____________" so you'll have to figure out how to fill those in if you want to go with this format. Again, I am here if you have any questions about anything

xjezzer:

Okay I will try it out, thank you very much

SmokeyBrown:

You're very welcome! I'll be here if you have problems getting it to work

xjezzer:

I'm not gonna be home for a bit so I'm gonna try it in a few hours

xjezzer:

I'm going to try it out now

xjezzer:

im confused in the blanks, is that where I put the methods?

xjezzer:

@smokeybrown for all the first and second blank, do I add the methods to make it uppercase and the second blank i need to use a method to make it count the amount?

SmokeyBrown:

Hi sorry for the extremely late reply. The first blank, in the while-loop, is the condition which keeps the loop running. Remember you want the program to continue until the user inputs "Q", so [hint] as long as the input is not "Q", the loop should continue. The second blank on line 16, "int length = _______________;" is indeed a function for finding the number of characters in the string. I listed it among the necessary components in my earlier post:

@smokeybrown wrote:
I go through the process in some detail in the comments of the code. Essentially: you use the Scanner object to take input from the user; you can use a while loop around the main body of code to allow the user to keep running the program until they input "Q" for quit; you can use the .toUpperCase() method for Strings to convert the input to uppercase; you can use the .length() method for Strings to find the number of characters in the input; you can use System.out.println() with "+" symbols and the variables you've stored to print the final output I've provided one possible way for you to put that all that together; feel free to make tweaks and adjustments as you need. Please DO NOT simply copy and paste the code I have written, this will be a disservice to yourself and your learning experience. (in fact, I might take some parts out of the code to make it incomplete so you will not be able to do this) And, again, let me know if there is anything I can help with or any questions you have.

xjezzer:

Can you check and see what I've done with the code

xjezzer:

Im not sure what to use for the output

SmokeyBrown:

Of course. I'll be happy to take a look at your product so far

SmokeyBrown:

I see you've edited the repl.it and replaced most of the blank spaces with the appropriate code. Well done! Some things about the while condition: First of all, the loop should continue as long as the input is NOT "Q", so instead of checking if the input is EQUAL to Q, the condition should check whether the input is NOT EQUAL to Q. Also, I think it might be better to use .equals() instead of == for String comparison. Lastly, the check should be for "Q" instead of "q", according to the original problem. Everything else looks good! As for the output, remember that the output message follows the format: "[UPPERCASE WORD] is [LENGTH OF WORD] characters long!" Based on this format, we can print a String to fit this format. I've made some of the changes in the repl.it based on my feedback. If there's anything you feel like you don't understand, please let me know :)

SmokeyBrown:

To clarify a bit about the while condition: We want the loop to keep running *until* the user inputs "Q". So, the only condition we need for the loop to continue is input NOT EQUAL to Q. The reason why [!input.equals("Q)"] is better than [input != "Q"] is because != not equals will check whether or not the comparison is literally just the character "Q". In fact, the input will always be a String object, not a literal character, so this condition will never be fulfilled. If we use .equals(), on the other hand, we can check what is stored *within* the String variable and see whether or not this is equal to "Q". That was a pretty bad explanation, but you can just understand that, in general, String comparisons should use .equals(), while numerical comparisons can use ==.

xjezzer:

You actually explained that really well. I appreciate you so much for your help

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Latest Questions
Bubblezz: Art for @euphoriiic
2 hours ago 23 Replies 3 Medals
ilovemybf: i need more drawing ideas
3 hours ago 15 Replies 1 Medal
toga: what is a Mayuri
7 hours ago 3 Replies 1 Medal
Midnight97: Here is a beat I made let me know what y'all think
7 hours ago 24 Replies 2 Medals
toga: who thinks that there should be more titles
8 hours ago 5 Replies 0 Medals
Midnight97: Can I get some help because I forgot how to do this
9 hours ago 5 Replies 2 Medals
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!