ITEC 1011 A, B,
Week 10 Lab Instructions
November 16, 17, 2000

 

Java Programming

Instructions


 

1.

Programming Challenge.  Write a Java program called Week10.java to perform as follows.  Prompt the user to enter a line of text on the keyboard.  Input the text as a string and analyze the string to determine the  following:

o        Number of characters in the string

o        First character in the string

o        Last character in the string

o        Number of digits in the string

o        Number of letters in the string

A sample dialogue follows: (user input is underlined)

     PROMPT>java Week10
     Please enter some text: Without doubt, #99 is The Greatest
     You entered 34 character(s)
     First character: W
     Last character: t
     Digits: 2
     Letters: 25
     PROMPT>

Hint:  A simple way to determine if a character is a digit is to use the isDigit() method in the Character class.  For example, if the variable c holds a character, then the expression

            Character.isDigit(c)

Returns true if c is digit, false otherwise.  A similar method called isLetter() tests if a character is a letter (a-z, A-Z).

Include comment lines at the top of the source file stating your name, student number, and the date.

Once the program is working properly, copy and paste the source code into the body of an e-mail message and send it to ta1011a@mathstat.yorku.ca or ta1011b@mathstat.yorku.ca.  (Make sure the source code includes the required comment lines.)  Use the following subject line:

            Nov19: lastname studentnumber

Finally, make a backup copy of your source file and name it Week10.bak.  This is just a precaution.  Hopefully you won’t need this.

 

3.

Free time.  The rest of this lab is free time to work on Assignment #5.

 

4.

Homework.  If you haven’t already do so, read Chapters 5 and 6 in the Java Primer.  Compile and execute all the example programs in these chapters.