Laboratory 6

Whiling away the lab

Week of Wednesday, 5 October, 2005


Home | Resources | Homeworks | Slides | Labs | Contacts | Submit | Forums

Objective

Being able to repeatedly execute statements of interest is a powerful programming mechanism. In this laboratory you will gain practice with the Java while looping statement.

This lab is a bit on the long side.  If you find yourself spending a lot of time on one part, ask a TA for help -- that's why they are there!

 

Key Concepts

 

Getting Started

Using the procedures in the previous laboratories (i.e. right-click on the link and select "save as"), copy the files SeriesSum.java, IntervalSum.java, Upper.java, CharacterCounting.java, One.txt and Two.txt for your manipulation.  All four of the Java files need to be submitted for this lab.

 

Determining sums of numbers

The first two while examples are concerned with computing sums of consecutive numbers. Although simple in nature, they illustrate nicely while loop behavior.

 

Text conversion

Often programs analyze text to see if it has some particular property. The next example program counts the number of uppercase letters in the text that it extracts. The program extracts its values from the standard input, which by default comes from the keyboard.  You will need to add the code so that the program also counts the total number of characters in the input.

 

Using Input File Streams

Often programs need to read and write data files. In this exercise, you will learn to use the Scanner class to read from a file instead of reading from the keyboard. Other types of file processing will be considered later.

 

Finishing up