Question
Create a new Java class called: ColorFinder In color theory, the primary colors of an additive color system are red, green, and blue. An example
Create a new Java class called: ColorFinder
In color theory, the primary colors of an additive color system are red, green, and blue. An example of a computer device which uses the additive color system would be your computer monitor, because it adds red, green, and blue light together to make all of the colors you see on your screen. The idea here is that the surface starts as black, and the monitor is adding light to make color.
The primary colors of a subtractive color system are magenta, yellow, and cyan. An example of a computer device which uses the subtractive color system would be your printer, because it mixes magenta, yellow, and cyan colored inks together to make all of the colors you see on paper. The idea here is that the surface starts as white, and we have to subtract light from it to produce the colors you see on the paper (which is why printing on colored paper will not produce the same colors as printing on white paper).
Write a program that gets a string from the keyboard and tests whether the string contains one of our primary colors. Your program should be able to find the primary colors, no matter what letters in the color are capitalized. For example, your program should be able to finds words like grEeN.
Begin by asking the user to type in a sentence.
Once you have the sentence, you should proceed to test it to see if it contains one of the primary colors.
If one of the additive colors is found in the sentence, print the message "Additive primary color found." to the screen.
If one of the subtractive colors is found in the sentence, print the message "Subtractive primary color found." to the screen.
If a sentence contains both additive and subtractive colors, you should print both messages "Additive primary color found." and "Subtractive primary color found." to the screen.
If none of the colors are found in the sentence, print the message "No primary colors found." to the screen.
The following is an example of what your MIGHT see on the screen when your program runs. The exact output depends on what values that the user types in while the program runs. The user's values are shown below in italics:
Enter a sentence: Roses are red, violets are blue. Additive primary color found.
Here is another example run of the program:
Enter a sentence: Aqua is a color that is similar to Cyan. Subtractive primary color found.
Here is another example run of the program:
Enter a sentence: Have you been to Yellowstone Park? Subtractive primary color found.
Here is another example run of the program:
Enter a sentence: Yellow is next to green in the rainbow. Additive primary color found. Subtractive primary color found.
Here is another example run of the program:
Enter a sentence: Black is technically not a color. No primary colors found.
Hints:
Refer to the JAVA documentation website to find the String methods that will help you accomplish your goals.
In order to deal with the possible ways that the user may mix upper and lowercase letters, you should begin by converting the inputted string to all lowercase (or all uppercase) letters. There is a String method to do this for you.
When trying to figure out if there is NOT a primary color in the sentence, do not attempt to re-test for all of the words again; this is too inefficient. Instead, use a boolean variable (also called a flag variable) to help you record when you have found a color in the sentence.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started