Repetition, files, and Colors
Learning Objective(s)
- Reinforce repetition
- Learn to use for statement
- Learn to read from a file
Overview of the Program
The program is to allow the user to guess colors in a file. The file contains numbers representing colors with 4 per row. The program is to allow the user to guess each color and output the number correct.
It is to also indicate if an entire row is correct.
Details
- Your colors are to be red, blue, green, and yellow.
- You must use constants for the colors and the number of colors per line in the file.
- Reject any invalid numbers (out of range)
- Use a for loop for the colors in one row
- Program should be called CheckColors
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
An example of the data file is:
1 1 1 1
2 2 2 1
1 2 3 4
An example of an acceptable dialogue:
What is the name of file? datafile
What is your guess for the next color on this line?
1
You got that one right!
What is your guess for the next color on this line?
2
You did not get that one right :(.
What is your guess for the next color on this line?
1
You got that one right!
What is your guess for the next color on this line?
2
You did not get that one right :(.
You got 2 right for that line.
What is your guess for the next color on this line?
2
You got that one right!
What is your guess for the next color on this line?
2
You got that one right!
What is your guess for the next color on this line?
2
You got that one right!
What is your guess for the next color on this line?
2
You did not get that one right :(.
You got 3 right for that line.
What is your guess for the next color on this line?
1
You got that one right!
What is your guess for the next color on this line?
2
You got that one right!
What is your guess for the next color on this line?
3
You got that one right!
What is your guess for the next color on this line?
4
You got that one right!
You got 4 right for that line.
Overall, you got 9 colors correct.
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
- I feel overwhelmed. How should I start?
- That was ok, but I am still overwhelmed. What else do you have?
- Hint for file problems
- Once the user gets 4 colors right, it seems like row is always guessed correctly no matter what
- I get too many lines of 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.
- Handle the exception of a bad file.
- Output the number of rows correctly