Sale!

CSC150 Assignment 8 solved

$30.00 $18.00

Original Work ?

Download Details:

  • Name: AssignmentEight-3smfrt.zip
  • Type: zip
  • Size: 62.45 KB

Category: Tag: You will Instantly receive a download link upon Payment||Click Original Work Button for Custom work

Description

5/5 - (1 vote)

CSC150 Assignment 8

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

public class VariableNameChecker
{
public static void main (String [] args)
{
String varName;
Scanner sc = new Scanner (System.in);
//prompt the user to enter a variable name
boolean valid = variableChecker(varName); // to check if it is legal
if (valid)
{
// your code to check for good style
}
else
{
// Illegal
}

// repeatedly prompt the user for variable names until the user enters “q” or “Q”
}

public static boolean variableChecker(String varName)
{
// your code

// return your variable.
} // end class
}

Notes:

  1. Do not forget to save a proper style in your VariableNameChecker.java file. Including comments and a program section at the top of the file. Proper style includes using a block comment at the top of your file that includes your name, class, section number, and a brief description of what the program does. The block lines should be aligned, with no superfluous indentation. The entire block should be aligned properly as specified.

  2. Maintain consistent brace control. Your program should have a consistent style for braces.

  3. As with the beginning of the class, the first should be a block comment that says what the class does.

  4. Follow the assignment instructions and make directed checks for legal/illegal variable names, then for variable names and camel case notation for style.

  5. To get full credit for all possible styles errors in the two given styles of variable names points will be deducted, even if your program is missing one.

  6. To get full credit for the assignment, your program must solve the