Selection and Color Matching

29 Dec 2022 - 12:30 | Version 1 |

Learning Objective(s)

  1. Learn to use the if statement
  2. Learn to use constants
  3. 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

  1. Use constants for numbers to represent each color. The user is to input a number (1-3) to represent a color.
  2. Be sure your prompts inform them as to what each number means
  3. If the colors are the same, you are to inform the user that they are the same and what color they are.
  4. 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

  1. create an empty zip folder
  2. place your java file into it
  3. create a pdf document that contains your Software Development Report for this program and place the pdf file into the zip folder
  4. submit the zip folder on canvas

Hints

  1. Hint for writing the selection component
  2. 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.
  1. 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.
  2. Have it also output what color is represent twice when two inputs are the same.
  3. Do the original program with only two if statements with at most three boolean expressions in each. You may also use one switch statement
  4. Have it reject any bad values
This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Foswiki? Send feedback
This website is using cookies. More info. That's Fine