


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
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
1 / 4
This page cannot be seen from the preview
Don't miss anything!



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