Tags:
tag this topic
create new tag
view all tags
---+ Repetition and Counting Colors ---++ Learning Objective(s) 1. Learn about repetition 1 Learn to use the *while* statement 1 Learn to reject some bad input 1 Learn to use the <b>switch</b> statement 1 Optional: Learn to use the <b>++</b> 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 1 Your colors are to be red, blue, green, and yellow. 1 You must use constants for the colors and the end of data 1 Have the user input 0 to indicate being done inputting 1 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. 1 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 <pre>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</pre> ---++ Submission a. create an empty zip folder a. place your java file into it a. create a pdf document that contains your Software Development Report for this program and place the pdf file into the zip folder a. submit the zip folder on canvas ---++ Hints 1. [[CSS121S2023Lab3H1][Program design]] 1. [[CSC121S2023Lab3H2][Hint for getting valid input]] 1. [[CSC121S2023Lab3H3][My code looks perfect but I am just getting 0's. I can't find the problem]] 1. [[CSC121S2023Lab3H4][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. 1 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 1 Have it properly (and nicely) handle the user entering 0 for the first color. 1 <b>Extremely advanced</b> Have it work with 25 different colors but only have one special variable to contain all the counters for individual colors.
E
dit
|
A
ttach
|
Watch
|
P
rint version
|
H
istory
: r2
<
r1
|
B
acklinks
|
V
iew topic
|
Ra
w
edit
|
M
ore topic actions
Topic revision: r2 - 2023-01-19
-
cathybareiss
Home
Site map
Assessment web
BethelAIResources2026 web
CenterForComputing web
ChatGPT web
Intro2AIatBethel web
Main web
Sandbox web
TWiki web
CenterForComputing Web
Create New Topic
Index
Search
Changes
Notifications
RSS Feed
Statistics
Preferences
P
P
View
Raw View
Print version
Find backlinks
History
More topic actions
Edit
Raw edit
Attach file or image
Edit topic preference settings
Set new parent
More topic actions
Account
Log In
Register User
E
dit
A
ttach
Copyright © 2008-2026 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki?
Send feedback