Explore BrainMass

Java program to memorize a sequence of colors

This content was STOLEN from BrainMass.com - View the original, and get the solution, here!

Write a program that tests the user's ability to memorize a sequence of colors. As shown in the sample session, the program starts off by displaying a dialog box with a list of colors that are to be memorized - red, white, yellow, green, and blue. The user then enters the colors one at a time in a text box. If the user makes a mistake, the program prints a "Sorry" message. If the user correctly enters all the colors, the program prints a "Congratulations" message. Note that when the sorry or congratulations message is printed, the window's original components get cleared away.

© BrainMass Inc. brainmass.com September 24, 2018, 9:46 am ad1c9bdddf - https://brainmass.com/computer-science/memory-management/java-program-to-memorize-a-sequence-of-colors-286293


Solution Preview

Please find below the java code. The list of colors are stored in the colors string array. Variable guessNumber keeps track of guess attempts made starting from 0 (it is easier to access color array items since they start from ...

Solution Summary

A java program in a single java file. When launched you will see a question "How good is your memory? Try to memorize following color sequence: [color list]". Then the form will appear where the user can enter his guess. If the user correctly enters all the colors, the program prints a "Congratulations" message. Solution is provided in two versions using JApplet or JFrame. Choose whichever required.