CISS-110 Project 2
This project uses some concepts from the textbook, including the String type, the Character wrapper class, and random numbers to work through performing multiple actions simultaneously in the program.
Learning outcomes
- Using a provided EOF loop, construct a solution.
- Implementing conditional constructs.
- Using random numbers.
- Working with strings and string operations.
- Using the
Characterwrapper class. - Confirmation program produces desired results.
You will be using an EOF loop. The details of loops will be discussed at length in the next module, but the EOF loop is pretty easy to master and provides a potentially endless input stream, making this project less tedious and more interesting.
Here is a framework to get you started:
import java.util.Scanner;
public class Project2_lastname {
static Scanner kb = new Scanner(System.in);
public static void main(String[] args) {
String input;
char c;
while (kb.hasNext()) {
}
}
}
Inside the EOF loop, you will perform the following:
- Prompt and read input from the user as a string.
- Using the string’s length, select a random character from the string.
- Determine the characters’ classification (see below).
- The output should provide what you read, the string length, the character position you randomly chose, and the character at that position.
Your categorization of the random character will include whether it is:
- A digit.
- Whitespace.
- Alphabetic – both upper and lower case.
- Punctuation. (This one is tricky and will be discussed in class.)
Here is a sample run that your program would produce. The user input is bold italic.
Please enter some characters and press enter: The quick brown fox jumps over the lazy dog! You entered: The quick brown fox jumps over the lazy dog! The string has a length of 44 characters. The character, chosen randomly from position 24, is 's'. That character is classified as a lowercase letter. Please enter some characters and press enter: DSUHF8483y4fhdf You entered: DSUHF8483y4fhdf The string has a length of 15 characters. The character, chosen randomly from position 7, is '8'. That character is classified as a digit. Please enter some characters and press enter: Q^$%Q*#&^$% You entered: Q^$%Q*#&^$% The string has a length of 13 characters. The character, chosen randomly from position 3, is '^'. That character is classified as a punctuation character. Please enter some characters and press enter: ^D
Note the CTRL-D entered by the user. This signifies they are done entering data. It may or may not appear in the output.
Submit the project to the Learning Management System as Project2_lastname.java.