Docsity

Programming Assignment 4 - Problem Solving and Programming Concepts | CIS 120, Assignments of Computer Science

Toggle sidebar
bg1
Name:__________________________________________________________________Section:___________
CIS 120-101 Fall 2007
Programming Assignment 4
Due: Week 7 (Fri 10/5/07)
Problem Description
Design and implement a program with a Java class called “Program4” that will ask a user to input a line of text to be analyzed. The
program will report on each line after it is entered and then go on to the next line to be input and analyzed. The program will stop its
analysis of lines when the user hits the cancel key in response to the given prompt. After the user hits the cancel key he will be given
the summary report based on all lines analyzed. The per input line analysis will report on the number of each vowel (a,e,i,o and u)
encountered (note both an ‘a’ and an ‘A’ will be included in the a-count) and the number of words found in the line. The summary
report (provided after the user hits the Cancel key to the input prompt) will show: (a) the number of lines analyzed, and (b) the total
number of each vowel found in ALL of the lines combined and (c) the total number of words found in ALL lines analyzed. You may
assume that words in the line are separated by a single space (or punctuation mark and a space). You may assume no “bogus” leading
spaces or trailing spaces will be used in the input lines.
Code Requirements:
Your code must use a do-while loop to control the reading and processing of lines to analyze and must use a for-loop to process each
individual line of input. You will be using “nested” loops in this assignment. Your summary output windows must have a title that
uses your name, not “(Faculty)”.
Hints: Your vowel and word counts (per line) must be reset to 0 for each new line to process. JOptionPane.showInputDialog()
returns a null if Cancel is hit, it returns a “” (a String of length 0 – NOTE: null and “” are NOT the same thing!) if the user hits enter or
the OK key without typing anything, and returns the String entered otherwise. String objects have two instance methods that will be
of use to you. They are: length() and charAt(somePosition). For example, if input is set to hold “Testing 1 2 3” then input.length()
would return a 13 (note that the 3 spaces in that String count towards its length too). The charAt instance method can be used to
return an individual char from the given String (but it starts its count at 0). Thus input.charAt(0) would return a ‘T’ and
input.charAt(12) would return a ‘3’. One can of course also use an expression like input.charAt(i).
You must submit a printed and electronic (CD or Floppy) copy of your commented program along with a printed copy of your
problem analysis, pseudocode, completed data dictionary, completed test design table and screen captures of the input and
output for all test cases in a manila envelope.
Problem Analysis - all inputs, processes, and outputs described. You must also include any formulas or constants in the problem
analysis.
Pseudocode – These steps should be detailed enough for you to transform each English-like statement into Java statements.
Data Dictionary (Add additional lines as required)
Variable Name Type Usage
aCount Int To keep the count of ‘a’s and ‘A’s in current line.
Test Design
Test
Case
Line entered a-count e-count i-count o-count u-count Word-count
1 Blank line 0 0 0 0 0 0
2
3
4
5
pf3

Partial preview of the text

Download Programming Assignment 4 - Problem Solving and Programming Concepts | CIS 120 and more Assignments Computer Science in PDF only on Docsity!

Name:__________________________________________________________________Section:___________

CIS 120-101 Fall 2007

Programming Assignment 4

Due: Week 7 (Fri 10/5/07)

Problem Description Design and implement a program with a Java class called “Program4” that will ask a user to input a line of text to be analyzed. The program will report on each line after it is entered and then go on to the next line to be input and analyzed. The program will stop its analysis of lines when the user hits the cancel key in response to the given prompt. After the user hits the cancel key he will be given the summary report based on all lines analyzed. The per input line analysis will report on the number of each vowel (a,e,i,o and u) encountered (note both an ‘a’ and an ‘A’ will be included in the a-count) and the number of words found in the line. The summary report (provided after the user hits the Cancel key to the input prompt) will show: (a) the number of lines analyzed, and (b) the total number of each vowel found in ALL of the lines combined and (c) the total number of words found in ALL lines analyzed. You may assume that words in the line are separated by a single space (or punctuation mark and a space). You may assume no “bogus” leading spaces or trailing spaces will be used in the input lines. Code Requirements: Your code must use a do-while loop to control the reading and processing of lines to analyze and must use a for-loop to process each individual line of input. You will be using “nested” loops in this assignment. Your summary output windows must have a title that uses your name, not “(Faculty)”. Hints: Your vowel and word counts (per line) must be reset to 0 for each new line to process. JOptionPane.showInputDialog() returns a null if Cancel is hit, it returns a “” (a String of length 0 – NOTE: null and “” are NOT the same thing!) if the user hits enter or the OK key without typing anything, and returns the String entered otherwise. String objects have two instance methods that will be of use to you. They are: length() and charAt(somePosition). For example, if input is set to hold “Testing 1 2 3” then input.length() would return a 13 (note that the 3 spaces in that String count towards its length too). The charAt instance method can be used to return an individual char from the given String (but it starts its count at 0). Thus input.charAt(0) would return a ‘T’ and input.charAt(12) would return a ‘3’. One can of course also use an expression like input.charAt(i).  You must submit a printed and electronic (CD or Floppy) copy of your commented program along with a printed copy of your problem analysis, pseudocode, completed data dictionary, completed test design table and screen captures of the input and output for all test cases in a manila envelope. Problem Analysis - all inputs, processes, and outputs described. You must also include any formulas or constants in the problem analysis. Pseudocode – These steps should be detailed enough for you to transform each English-like statement into Java statements. Data Dictionary (Add additional lines as required) Variable Name Type Usage aCount Int To keep the count of ‘a’s and ‘A’s in current line. Test Design Test Case Line entered a-count e-count i-count o-count u-count Word-count 1 Blank line 0 0 0 0 0 0 2 3 4 5

Sample execution:

Input line 1

Analysis after entry of line 1:

Input line 2 (hit Enter with no typing)

Analysis displayed after empty line entered:

Input line 3

Analysis after entry of line 3.

Input 4 requested. We hit Cancel button.

Summary report produced after Cancel hit.