CSC1110: Homework Week 4
Part 1: CodingBat
If you haven't already, create a codingBat account using your msoe email address. In the top right corner, click the prefs links and add me (velez@msoe.edu) in the Teacher Share field. This will share your codingBat results with me so that I can grade it. If you do not do this, I can not grade your codingBat progress.
Complete the following CodingBat problems
farEnough
makeChange
sumDigits
middleThree
Part 2: Complete the following program
Write a program called VariableNameChecker
that checks the properness of a given variable name.
Your program should prompt the user for a variable name or q to quit. After each entry, you should tell the user
whether the variable name is good, illegal, or legal but poor style. See the sample output below. Because the user may
enter a variable name with spaces, you should use the appropriate Scanner command to deal with an input that has spaces.
In your program, you must have and use methods called isGoodStyle() and a method called isLegal().
- isGoodStyle() takes in a String and returns true if that String follows the style convention of only using letters and digits and having the first character be lowercase. You don’t need to check for an uppercase letter for the first letter in the second word, third word, etc.
- isLegal() takes in a String and returns true if that String is a legal identifies in Java. You should refer to textbook for what is and is not a legal name in Java.
Sample session output
This program checks the properness of a proposed Java variable name. Enter a variable name (q to quit): streetAddress2 Good! Enter a variable name (q to quit): street address2 Illegal. Enter a variable name (q to quit): StreetAddress2 Legal, but uses poor style. Enter a variable name (q to quit): 2ndStreetAddress Illegal. Enter a variable name (q to quit): street_address$2 Legal, but uses poor style. Enter a variable name (q to quit): street#address2 Illegal. Enter a variable name (q to quit): q
Submission
Make sure you are logged into CodingBat so your progress is saved. See your professor's instructions for details on submission guidelines and due dates.