COSC 060 Introduction to Software Problem Solving
Fall 2008
Lab Assignment #2
"There is geometry in the humming of the strings, there is music in the spacing of the spheres."
-- Pythagoras, Greek philosopher and mathematician (BC 580-500)
Due: Thursday, September 4th, End of Lab Session
Submit: Turn in your "Lab2.java" using the turnin command
on Morbius.
Work is to be completed individually. You may submit multiple times, but
only the last turnin will be kept. The automatic submission system will
not accept work after the deadline.
Strings Are The Things
Four short exercises on the theme of character Strings, five
points each.
#1: Write a class "Lab2" that reads in a line of text, prints it
back out, and gives the length of the line. Use the Scanner
class.
#2: Extend your class to print the first character of the String,
the last character of the String, and the middle character of the String.
Round down if there is no middle character.
#3: Extend your class to print the String in all upper case letters,
and then all lower case letters.
#4: Extend your class to split the String up roughly into four
quarters, printing each piece separately. Use the String
class's substring() method.
Documentation on the String class can be found both in chapter 2 of the
textbook, and online at Sun's Java API.
Example Run
Please enter a line of text:
Who goes there?
Your line was "Who goes there?".
The line is 15 characters long.
The first character is 'W'.
The last character is '?'.
The middle character is 's'.
In all upper case: "WHO GOES THERE?".
In all lower case: "who goes there?".
First quarter: "Who".
Second quarter: " goe".
Third quarter: "s t".
Fourth quarter: "here?".
Back
[Revised 2008 Sep 03 23:26 DWB]