/** * CS139 - Programming Fundamentals * Department of Computer Science * James Madison University * @version Spring 2016 */
Use a loop structure for error correction.
Use a loop structure for execution control.
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!
Download the EightBall.java program. Read through the code and try running it. Ask the instructor about any lines you do not understand.
The provided program code prompts the user for a question and then "shakes" the 8 ball to get an answer. It also checks to see if the question is too long. In this variant, you will not end the program, but instead ask the user to enter a shorter question as follows.
If the String
is longer than 60 characters, print out
an error message, "Your question is too long. Be more
concise.\n"
. Re-prompt the user and read in the question
again. ("What is your question?\n"
) Continue checking for
the length until the user enters a question less than or equal to 60
characters. Test your code after making this change.
"Your question is too short. Please try
again.\n"
. Once again, the user should be re-prompted until
they enter a valid question. Test your modifications."You
need to ask a question.\n"
. Test your modification. (HINT: The endsWith
method of the String
class will probably be useful here.)
"Do you want to ask a question
(yes/no)?"
Your final version should allow you to keep asking questions until you enter the word no, and it should verify that each question has an appropriate length and ends with a question mark. Submit your final EightBall.java file via Canvas.
Complete as many exercises as possible in the
Codingbat Logic-2
section, starting with makeBricks
. (Note that these are
challenging problems. There are some pages of advice for
the makeBricks
problem. Feel free to take advantage of
the help if you get stuck.)