Learning Objective(s)
- Reinforce repetition
- Learn to use methods
- Learn to manipulate strings
Overview of the Program
The user inputs two strings and then outputs which how many colors in the second string are in the exact same position as in the first string.
Details
- Your colors are to be red, blue, green, white, and yellow.
- The user inputs the colors as single letters as seen in the example dialogue.
- Each string is to be checked for being valid and if it is not valid, re-inputted until it is.
- Write the method getValidResponse that gets a valid string from the user and returns that string
- Write the method numCorrect that receives the two strings and returns the number of characters that are exactly the same
- Write the method isValidColor that receives a character and returns if it is valid
- Write the method isValid that receives a string and returns if it is valid. It is valid if it is the right length and all of its colors are valid colors.
- You must use constants for the colors and the number of colors in a string.
- Program should be called ColorTools
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.
The strings should be exactly 4 characters long.
The color are r (red), b (blue), w (white), g (green) and y (yellow)
What is the given color sequence? rrgb
What is the comparing sequence? brgw
2 colors are exactly right.
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
- How do I get find out things about a string
- Help on isValidColor
- Help on isValid
- Help on getValidResponse
- Help on numCorrect
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. You must score at least 90% on the rest of the program to earn any additional points
- Read the first string from a file.
- Also count the number of colors that are in the first string but not in the right space and output that value
- Handle the exception of a bad file.
- Output the number of rows correctly