Selection and Color Matching
Learning Objective(s)
- Learn to use the if statement
- Learn to use constants
- Write your first program on your own
Overview of the Program
For this program you are to get three colors choices from the user (red, green, blue) and then inform the user if they are all the same or all different.
Details
- Use constants for numbers to represent each color. The user is to input a number (1-3) to represent a color.
- Be sure your prompts inform them as to what each number means
- If the colors are the same, you are to inform the user that they are the same and what color they are.
- Program should be called ColorMatcher
Example program dialogue:
These are not meant to be sufficient testing. Nor must you follow the exact wording. They are just to demonstrate what an acceptable program might do for certain input
Example 1:
What is your first color (1=blue, 2=red, 3=green)
1
What is your next color?
1
What is your third color?
1
They are all blue.
Example 2
What is your first color (1=blue, 2=red, 3=green)
1
What is your next color?
2
What is your third color?
3
The colors are all different
Example 3
What is your first color (1=blue, 2=red, 3=green)
2
What is your next color?
2
What is your third color?
3
Program design
- Necessary code and banner comment
- class
- declare constants
- main method
- declare variables
- input with prompts
- conditional output
Submission
- create an empty zip folder
- place your java file into it
- create a pdf document that contains your Software Development Report for this program and place the pdf file into the zip folder
- submit the zip folder on canvas
Hints
- Hint for writing the selection component
- Hint if your code is starting to get complex
Optional improvements
Optional improvements should ONLY be worked on once the program is completing working. In addition, the work is to be done on your own with little if any help for lab assistants or the instructor.
- Allow the user to type in the color as a word. Convert that word to the appropriate number in your code. For more of a challenge, allow the user to use upper or lower case as they wish.
- Have it also output what color is represent twice when two inputs are the same.
- Do the original program with only two if statements with at most three boolean expressions in each. You may also use one switch statement
- Have it reject any bad values