In this lab, you will refactor the program you wrote for Lab 9. Your program will consist of the same classes as last time; however, the BioProgram class (to be put in the msoe.se1011.<yourname> package) must now contain the additional class "helper" methods as illustrated in the following class diagram:
In addition, you'll be changing the program to store the heartrate values in an ArrayList<Integer> rather than an int[ ] array.
Begin the refactoring by replacing all occurrences of the int[ ] array with ArrayList<Integer>. Get the program running again with this change in place before adding the methods described below.
One helper method, inputUserValue, is to contain the instructions that prompt a user for numerical input, validate that input, and return the result. This method is to be called for each of the input values for lower limit, upper limit, and aerobic threshold, thereby eliminating a lot of duplicated code. The following Javadoc comments explain this method more fully:
/** * The inputUserValue method prompts the user to enter some information via a dialog, validates the input, and returns the value. * If the user inputs a value that is out of range or presses OK with no value entered, the prompt is repeated. * If the user presses Cancel, the method returns the value Integer.MIN_VALUE. * @param title the title of the dialog * @param prompt the prompt to display * @param lowerLimit the lower limit that is acceptable for the value * @param upperLimit the upper limit that is acceptable for the value * @return the value input by the user, converted to an integer, or Integer.MIN_VALUE if the user pressed Cancel. */
The second helper method, computeMetrics, simply analyzes the values in the collection and computes the max, min, and average values of that data:
/** * The computeMetrics method computes the average, maximum, and minimum values of the elements in the specified array * @param values ArrayList<Integer> of values to be processed * @return none. The average, maximum, and minimum results are stored in the class attributes average, max, and min. */
Note that the average, max, and min values are class attributes (as indicated above in the class diagram) in this refactored version of the program, rather than local variables only visible in the main() method. This is needed because both main() and computeMetrics() methods need to "see" these variables, so the visibility scope has to be increased to the class level.
The UML Sequence diagram for the refactored program, showing the general time-sequence of method calls is:
Submit your assignment following these instructions:
Be sure to keep copies of all your java files, in case something gets lost.
Your grade will be based on the following criteria: