CS 239 Advanced Programming
Lab239-L01B: Introduction to Design

Objectives

The students will be able to:

Background     

If you look at a word processing application such as Word, it has the ability to count various features of the document, such as number of words and number of characters. This application will let you explore how they might have done that. Bring a copy of your program to class tomorrow in either hardcopy form or electronically.

New Terms

parse
To analyze or separate (input, for example) into more easily processed components.

Materials Used

This application will be written from scratch.

 


Part 1

Using the Scanner class, write a short program that prompts the user for a sentence.  After accepting the user's entry, the program should display what the user entered in the form:

 You have entered [ user entry ].

You will only use the nextLine() method to read in a full line from the keyboard.

Part 2

Following the output above, tell the user in parentheses whether what they entered was an int,  a double, a char, a boolean value (true/false), or a String. You may not use any of the Scanner methods to try to "parse" the user's input but instead must try and figure out based on the characters entered what kind of "thing" the user entered.

For example, if the user enters in "1", you would report:

   You have entered 1 (int)

If the user enters in "1.4", you would report:

 You have entered 1.4 (double)

and so on.

Look at the methods for the String class in the Java documentation.  Some methods you might find useful here are:

The more experienced among you might want to use a try/catch block along with Exceptions.  I would prefer you work this out the hard way, by parsing what the user entered and figuring out from that what it must be.

When you are finished, bundle your files into a zip file.  You can do this from the command line in Linux in the form: 

   zip < name of zip file > [List of files to include - wildcards can be used here]

The name of the zip file should combine the lab number and the last names of each member of the pair (or a single last name if solo).  For example:

   zip Lab2NortonHarris.zip *.java

This will create a file called "Lab2NortonHarris.zip" that includes all files that end with .java in the current directory).  Submit the zip file to the Blackboard assignment BEFORE the beginning of the next class period.


created by Michael Norton
last updated 01/06/13 - nlh