We have already worked with if statements to detect invalid input. But in some cases users will repeatedly enter the wrong value. In addition, some problems lend themselves to executing the program repeatedly. This lab will explore these uses of loops in Java.
Use a loop structure for error correction.
Use a loop structure for execution control.
Java String API - This page contains a list of all the methods for the String class. Clicking a method in the "Method Summary" chart will take you to a more detailed description of that method.
The Magic 8-Ball is a toy produced by Tyco Toys (now Mattel) and consists of a ball filled with a blue fluid. Suspended in the fluid is a icosahedron (a 20-sided polyhedron with each side consisting of an equilateral triangle). Each face has an answer to a yes/no question. Check out this link to see what a Magic 8-Ball looks like on the inside
nextLine
method can read in an empty string. If the question is empty (zero length), you should tell the user that's not allowed and then prompt for and read in the question again. Do this until the user enters a valid string.'?'
character. Check the question string and make sure that it ends with a question mark. Be careful...the empty string has no characters in it. If there is no question mark, tell the user that they need to ask a question mark and repeat as before.Your final version should allow you to keep asking questions until you enter the word no, and it should verify that each question is at most 60 chars ending with a question mark. Submit your final EightBall.java file via Autolab by 11 pm Wednesday.
If you have not already done so, refer to Part 1 of the first Coding Bat Lab to set up your JMU account on codingbat.com. Remember to log in before doing any problems so you will receive credit.
int[]
. Don't worry about those problems; we'll get to that topic next weekSee how many of the String-1 problems you can solve today. None of these problems require any loops. At a minimum, solve the following:
firstHalf, endsLy, and conCat.
See how many of the String-2 problems you can solve today. Each of these problems requires ONE loop. At a minimum, solve the following:
doubleChar and catDog.
You may find (on CodingBat's site) the Java String Introduction useful.