CS99 |
Fundamental Programming Concepts
Summer 2001 |
|
Lab
7
Reading for next lab: 4.1 Savitch. We'll introduce classes and methods in Lab 8.
|
||||
Overview | ||||
The goals of this lab are to:
|
||||
Part I: More star patterns, nested whiles | ||||
In
the sub-portions of this part of the Lab, you may use only the following
types of print statements
Part
A:
Part B:
Part C:
Part D:
Note that there are spaces between each star. Print and submit copies of each of the parts in files with names Lab7Part1A.java, Lab7Part1B.java,
Lab7Part1C.java, and Lab7Part1D.java. |
||||
Part II: Vowels, using chars | ||||
Write a program that reads a string from the user, then determines
and prints how many of each vowel (a,
e, i,
o, and u)
appear in the string. Have a
separate counter for each vowel. Also
count and print the number of non-vowel characters.
All in all, you'll need at least 7 or 8 variables.
Use the String function charAt() (introduced in Lab 6) to test the type
of characters at each location in the String. (Later, when we start to use
arrays, you'll see how to make a question like this much easier!)
|
||||
Part III: Finding the Mode, stopping values | ||||
Write a program that reads in a sequence of non-negative grades and
prints out the "mode" and its frequency.
"Mode" is the technical term for "a value that occurs with
maximum frequency". Note that
there can be more than one mode. In
the list 87 92 92 92 98 98 99 99 99 100, both 92 and 99 are modes that occur
with the maximum frequency 3--every other value in the list occurs with smaller
frequency 1 or 2. For the input, ·
Assume the grades are sorted in ascending order (can you see why
this is necessary?) ·
Assume the sequence is terminated by -1 ·
If there is more than one mode, it doesn't matter which one the
program prints A rough outline for your program should be: <read first grade> <initialize other variables> while ( < grade
entered is not -1 > ) {
<process current grade>:
is current grade same as the previous grade?
if yes, update frequency of previous grade
if no, start a new frequency for current value
do we have a new mode?
update mode
<update previous grade>
<read next grade> } <print
output> You
should use the following variables in your program: grade, mode,
modeFreq, prev,
prevFreq. (Once you start
writing the program you'll realize why these variables are necessary.) Your
program should be designed in such a way that it prints an appropriate statement
when there is no input for a mode to be determined (i.e., when the user enters
in -1 as the very first number). Save and submit a copy of this program in a file called Mode.java. |
||||
Part IV: Submit Your Lab | ||||
Hand in printouts for
As
usual, don't forget to put your name, net ID, and date at the
top of each file. This lab is due Thursday, 19 July 2001 at the beginning of the lab
session. Hand it in to Siddharth as
usual. |