CIS 120-101 Fall 2007: Java Program for User Input & Calculation of Sum, Average, Min, Max, Assignments of Computer Science

A programming assignment for a java class named 'program3'. The assignment requires students to create a program that asks users for the number of integers they want to input, validates the input, and then calculates the sum, average, minimum, and maximum of the entered integers. Students must use a looping structure and joptionpane for output. Hints and filename requirements are also provided.

Typology: Assignments

Pre 2010

Uploaded on 08/17/2009

koofers-user-v75-2
koofers-user-v75-2 🇺🇸

10 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Name:__________________________________________________________________Section:___________
CIS 120-101 Fall 2007
Programming Assignment 3
Due: Week 6 (Fri 9/28/07)
Problem Description
Design and implement a program with a Java class called “Program3” that will ask a user how many numbers that he would like to
input (you may assume that the user will input some integer or hit the cancel button). If the user hits the cancel button exit the
program saying that you are doing so (see sample output). If the user says that he want 0 numbers generate a screen that shows that no
numbers were entered thus there is no sum , average, minimum or maximum (see sample output). If the user enters a negative number
then give him an error message and exit the program (see sample output). If the user says he wants to enter some positive number of
numbers (e.g. 3) then you are to loop that number of times asking him to input a number (e.g. 3 times asking him to input an integer).
As you are getting these inputs you should track (a) the sum of them, (b) the maximum value seen, (c) the minimum value seen. After
the last of his numbers has been entered, you should use JOptionPane to report the number of integers entered, the sum of those
integers, the average of those integers, the minimum of those integers and the maximum of those integers (see sample output on next
page). If during the input of those integers he hits the cancel button you should show a screen saying so and exit the program.
Code Requirements:
Your code for prompting the user for integer input, doing comparisons to find the current maximum, current minimum, and current
sum must be performed inside a looping structure. Your output windows must have a title of “Program 3 (Your Name)” with an icon
of the correct type..
Error Checking:
You should handle the case of the user clicking cancel on ANY of the input dialog boxes. If he does click cancel at any point you
should produce a screen saying that the Cancel was hit and that the program is terminating. You are not required to error check for
non-integer String input.
Hint: The first time through your looping structure you will want to initialize your variables for the current maximum, current
minimum and sum to the first integer inputted. Since you only want to do this initialization one time, you may want to do something
like the following code after you have asked the user to input an integer and performed the appropriate error checking:
if (firstIteration) // firstIteration will be a boolean variable initialized to true outside the loop body
{
// initialize max, min, sum to inputted number
// set firstIteration to false
}
Hint: Use Google to do a search on Java JOptionPane if you need to read more online about that class method. (1st choice)
Filename Requirements: Your program must be saved to a file called Program3.java
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 5 test cases in a manila envelope. Hint: when a desired window is showing you can capture the screenshot to the
Windows clipboard by hitting Alt-PrintScreen. You may then inside of your word processor use Paste (Ctrl-V) to paste that
clipboard screen image into your file (your screen shots for all test cases run must be submitted with your assignment).
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 (You may add additional lines)
Variable Name Type Usage
pf3
pf4

Partial preview of the text

Download CIS 120-101 Fall 2007: Java Program for User Input & Calculation of Sum, Average, Min, Max and more Assignments Computer Science in PDF only on Docsity!

Name:__________________________________________________________________Section:___________

CIS 120-101 Fall 2007

Programming Assignment 3

Due: Week 6 (Fri 9/28/07)

Problem Description Design and implement a program with a Java class called “Program3” that will ask a user how many numbers that he would like to input (you may assume that the user will input some integer or hit the cancel button). If the user hits the cancel button exit the program saying that you are doing so (see sample output). If the user says that he want 0 numbers generate a screen that shows that no numbers were entered thus there is no sum , average, minimum or maximum (see sample output). If the user enters a negative number then give him an error message and exit the program (see sample output). If the user says he wants to enter some positive number of numbers (e.g. 3) then you are to loop that number of times asking him to input a number (e.g. 3 times asking him to input an integer). As you are getting these inputs you should track (a) the sum of them, (b) the maximum value seen, (c) the minimum value seen. After the last of his numbers has been entered, you should use JOptionPane to report the number of integers entered, the sum of those integers, the average of those integers, the minimum of those integers and the maximum of those integers (see sample output on next page). If during the input of those integers he hits the cancel button you should show a screen saying so and exit the program. Code Requirements: Your code for prompting the user for integer input, doing comparisons to find the current maximum, current minimum, and current sum must be performed inside a looping structure. Your output windows must have a title of “Program 3 (Your Name)” with an icon of the correct type.. Error Checking: You should handle the case of the user clicking cancel on ANY of the input dialog boxes. If he does click cancel at any point you should produce a screen saying that the Cancel was hit and that the program is terminating. You are not required to error check for non-integer String input. Hint: The first time through your looping structure you will want to initialize your variables for the current maximum, current minimum and sum to the first integer inputted. Since you only want to do this initialization one time, you may want to do something like the following code after you have asked the user to input an integer and performed the appropriate error checking: if (firstIteration) // firstIteration will be a boolean variable initialized to true outside the loop body { // initialize max, min, sum to inputted number // set firstIteration to false } Hint: Use Google to do a search on Java JOptionPane if you need to read more online about that class method. (1st^ choice) Filename Requirements: Your program must be saved to a file called Program3.java 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 5 test cases in a manila envelope. Hint: when a desired window is showing you can capture the screenshot to the Windows clipboard by hitting Alt-PrintScreen. You may then inside of your word processor use Paste (Ctrl-V) to paste that clipboard screen image into your file (your screen shots for all test cases run must be submitted with your assignment). 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 (You may add additional lines) Variable Name Type Usage

Test Design Test Case Number of integers Integers entered max min sum average 1 0 N.A. N.A. N.A. N.A. N.A. 2

CIS 120-101 Fall 2007

Programming Assignment 3 Cover Sheet Grade _______________

Name (Print): __________________________________________ Student #: _____________

Instructor: _____________________________________________ Section: _______________

Your program documentation should be labeled and organized according to the following:

DOCUMENTATION and DESIGN: 25% Paper copy and electronic copy are mandatory.

_____5 pt. Problem Analysis

Identification of inputs, processes, and output

_____5 pt. Algorithmic Design:

Pseudocode – Clearly Written and Understood

Correct Solution

_____5 pt. Data Dictionary

All data and data types specified

Appropriate names chosen

Correct data types chosen

_____10 pt. Test Design (5%) and corresponding program output (5%)

Minimum of five documented test cases with screen captures of the associated

input/output for each case.

Displays correct input and output expected by program.

Output is clear and correct.

Your program should have proper global documentation (at the top). It should also have appropriate internal

documentation with code lines. See lab 1 programs for an example.

PROGRAM: 75% Paper and electronic copy of your source code submitted in a manila envelope.

_____10 pt. Internal documentation and comments

_____10 pt. Style (indentation, spacing, blank lines, correct capitalization of identifiers based on

coding convention, etc.)

_____ 5 pt. Meaningful identifiers - matches data dictionary

_____35 pt. Correctness of program

Including: Program compiles, program runs, produces correct output

_____15 pt. Follows algorithm

Please note : additional points may be deducted if the package submitted does not contain all of the required

contents in an acceptable format.