, ,

[SOLVED] Csc150 assignment 8

$25

File Name: Csc150_assignment_8.zip
File Size: 178.98 KB

5/5 - (1 vote)

which your program should repeatedly check a given string variable name to determine if it is a legal Java identifier, and if it is, whether or not it has good style. The only legal characters in a Java identifier are letters, numbers, underscore (_), and dollar sign ($). A Java identifier may not start with a number, and it may not be a reserved word such as class or public. You should also check that it has good style: the name should start with a lowercase letter and should use camelCase rather than under_scores or ALL_CAPS. Your program should use a method
public static boolean variableChecker(String varName)
that returns true if the given string is a legal variable name and false if it is not. You may want to look at the Java documentation for the Character class, which has methods that can be useful for this problem.

Camel case means capitalizing the first letter of each word except the first. You should also check for the opposite problem: the first letter is the second word capitalized when it should not be.

Your program should repeatedly prompt the user for variable names until the user enters “q”. The program terminates when the user enters the “q” or “Q” command.

Sample session:
This program checks the properness of proposed Java variable name.
Enter variable name (q or Q to quit): coffee2Go
Good!
Enter variable name (q or Q to quit): $coffee2Go
Illegal variable name.
Enter variable name (q or Q to quit): SomeName
Legal but uses poor style.
Enter variable name (q or Q to quit): someNameAndOther
Legal and uses good style.
Enter variable name (q or Q to quit): some_name
Legal but uses poor style.
Enter variable name (q or Q to quit): q

Notes:

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] Csc150 assignment 8[SOLVED] Csc150 assignment 8
$25