CST 112 -- Quiz #2 [aft]


Write Java code for these new methods:

factorial( int n )
returns n!, the factorial of its argument.
(If n is 5, then n! = 5 * 4 * 3 * 2 * 1 == 120 ; note that 1! is 1 and 0! is 1).

sumDig( int n )
returns the sum of the digits.
sumDig( 11901 ) returns 12

isMult( int, int )
returns true iff the first argument is a multiple of the second argument.
isMult( 51, 17 ) returns true

isVowel( char )
returns true iff the argument is a vowel [aeiouAEIOU]
isVowel( 'E' ) returns true; isVowel( 'j' ) returns false;

isConsonant( char )
returns true iff the argument is a letter, but NOT a vowel.
Be sure to use library functions such as toUpper, and isLetter,

In the main() method, add code to do the following tasks.

  // Note that these tasks are also described in comments within the main() method:

  //  TASK 1. Count the number of consonants in each String (firstName and lastName),
  //  	then print a message saying which one (if any) has more of them.
		
  //  TASK 2. Check whether area code has exactly three digits; print error message if not.
  //  	Check whether zipcode has exactly five digits; print error message if not.
 	
  //  TASK 3. Check to see if each number (zipCode and areaCode) is divisible by
  //  	any of the first six primes (2, 3, 5, 7, 11, 13).

  // TASK 4. Calculate and print the factorials of the numbers one to twelve.
  //  	(12! == 479,001,600)
	
  // TASK 5. Prompt the user to enter a password; check if it follows these rules:.
  //  	-- between five and fifteen characters long.
  //  	-- exactly three digit characterss.
  //  	-- more consonats than vowels.
  //  	-- at least one character that is not a letter or number.


		// OPTIONAL:  Instead of writing code here (in main), 
		// OPTIONAL:  write a separate method for each of the above
		// OPTIONAL:  and call it with appropriate arguments.

Add code to the main( ) method, to calculate the following:


NOTE:   For this in-class quiz, each of the five tasks and five answers is worth 10 points, plus or minus 2 for modularity, readbility, and good programming style, for a maximum of 12. Therefore, it is possible to earn a grade of "A" by skipping two, and doing eight of them perfectly! (On the quiz, quality is far more important than quantity, so it pays to do well on the ones that you can do!)

On the "redo" however, each is worth a maximum of ten, and it is necessary to do all to get a good grade.

Also, please note that submitted Java code that has syntax errors and fails to compile will NOT be graded, and will receive a grade of zero! Make sure that your code compiles properly, before submitting it!