Repetition and Counting Colors
Learning Objective(s)
- Learn about repetition
- Learn to use the while statement
- Learn to reject some bad input
- Learn to use the switch statement
- Optional: Learn to use the ++ operator
Overview of the Program
For this program you are to get count the number of each type of color inputted by the user and output the percentage for each color
Details
- Your colors are to be red, blue, green, and yellow.
- You must use constants for the colors and the end of data
- Have the user input 0 to indicate being done inputting
- Use a switch statement to decide which variable to increment. You may use an if statement if you wish but you will lose a few points.
- Program should be called ColorCounter
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
What color (1=blue, 2=red, 3=green, 4=yellow, 0=end)
1
Next color?
2
Next color?
5
That was not a valid choice. Again?
1
Next color?
2
Next color?
0
The % of blue was 0.5
The % of red was 0.5
The % of green was 0.0
The % of yellow was 0.0
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
- Program design
- Hint for getting valid input
- My code looks perfect but I am just getting 0's. I can't find the problem
- Help to debug a program that compiles but does not generate the right output
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 input the colors as a string and the code not be case sensitive. Do not use strings in the switch statement
- Have it properly (and nicely) handle the user entering 0 for the first color.
- Extremely advanced Have it work with 25 different colors but only have one special variable to contain all the counters for individual colors.