# ASSIGNMENT 2 Cryptography COMP-202 solved

\$35.00

## Description

5/5 - (1 vote)

Warm-up Question 1 (0 points)
Write a method printTypeOfChar. This method should take as input a char and print the type of
character. If the char is upper case, your method should print UPPERCASE. If the char is lower case,
your method should print LOWERCASE. If the char is any other symbol, your method should print SYMBOL.
Note that it is not necessary to make 52 different cases if you consider the order of the Unicode chart
and the fact that you can use the < and > operators on them.
Warm-up Question 2 (0 points)
Write a method countUppercase. Your method should take as input a String and return an int
representing the number of upper case letters in the String. Now add a main method where you use
the Scanner class to read a String from the user and call your method, outputting the returned result.
Warm-up Question 3 (0 points)
Write a method toUpperCase which takes as input a String and returns another String which is
the original String but with all lower case letters converted to upper case. Any letters that are not
lower case should remain the same. Do NOT use any methods in the Character class or the
.toUpperCase() method in the String class
For example the input String of “Hi!” should become “HI!”
Warm-up Question 4 (0 points)
Write a method reverseString which takes as input a String and returns the string in reverse order.
For example if the input String is “Comp 202 is awesome” the result should be “emosewa si 202 pmoC”
Hint: Use a new String called reverse and initially store into it the empty String. Then read the
input String in reverse by using the method .charAt(int i) to get a specific element.
Warm-up Question 5 (0 points)
A prime number is a positive number whose only even divisors are 1 and itself. Write a method isPrime
Page 2
that takes as input an integer n and returns a boolean representing whether n is prime or not. Make
sure to handled cases where the integer is negative. (Your method should return false in these cases.)
Warm-up Question 6 (0 points)
Write a method firstPrimeNumbers which takes as input an int n and returns an int[] . The int[]
should contain the first n prime numbers.
Warm-up Question 7 (0 points)
Practice using the utility code we have provided by calling the method countEnglishWords() from the
SentenceChecker class. To ensure things work, put all files (web2.txt, SentenceChecker.java, and your
new class) into the same directory. You can then leave both SentenceChecker.java and your new class
open at the same time in Dr. Java.
The method countEnglishWords takes as input a String and returns how many English words are part
of it, using a list of words provided in the file web2.txt. Try calling this method to check how many
English words are in the sentence The laydee hit teh man wit the bay bee.
Warm-up Question 8 (0 points)
Practice using the Random class: Question four requires using the Random class. In this warmup question,
you will generate random numbers.
Write a method that takes as input an int n and an int max and returns an int[]. The array you
return should be an array of size n and filled with n random numbers between 0 and max, counting 0,
but not counting max. Assume max is a positive number.
See the instructions within question 4 for help using Random class.
Warm-up Question 9 (0 points)
Same question as before except your method should now take as input three values: int n , int min,
and int max. Instead of ranging from 0 to max, you should range from min to max.
Again, you may assume both min and max are positive numbers as well as assume that min is less than
max.
Warm-up Question 10 (0 points)
x is a factor of y if y is a multiple of x. Write a method calculateFactors. The method should take
as input an int n and return an int[] containing all the factors of the number n
Warm-up Question 11 (0 points)
Write a method that takes as input an array of Strings and prints all of the Strings on separate lines.
Warm-up Question 12 (0 points)
Create a file called Counting.java, and in this file, declare a class called Counting. This class should
ask the user when the computer should stop counting.
When should I stop counting to?