Question: Chapter 7 Programming Challenge 1 1 Starting out with Java Tony Gladdis 4 th Edition - Must Follow Templates ArrayData must be usable without instances.

Chapter 7 Programming Challenge 11 Starting out with Java Tony Gladdis 4th Edition -Must Follow Templates ArrayData must be usable without instances.
ArrayData methods must scan arrays "up", from lower indexes to
higher.
ArrayData methods must use loop counters that count down.
ArrayData methods shall assume that the arrays are of ints.
Must not have the same conceptual task coded in more than one place.
Bonus: ArrayData calculates the total, highest, and lowest by using a single
loop.
*/
public class Ch07Pc11_ArrayDataTEMPLATE
{
public double getTotal(double[] nums)
{
double total = nums[0];
for (int i=1; i < nums.length; i++)
{
total += nums[i];
}
return total;
}
public double getAverage (double[] nums)
{
double total = nums[0];
for (int i=1; i < nums.length; i++)
{
total += nums[i];
}
return total / nums.length;
}
public double getHighest(double[] nums)
{
double maxNum = nums[0];
for (int i=1; i < nums.length; i++)
{
if (maxNum < nums[i])
{
maxNum = nums[i];
}
}
return maxNum;
}
public double getLowest(double[] nums)
{
double minNum = nums[0];
for (int i=1; i < nums.length; i++)
{
if (minNum > nums[i])
{
minNum = nums[i];
}
}
return minNum;
}
} Array Test Template: Input is read from the ArrayVals.txt file
(Create the file with the values: 51549070-52)
-- note that it is far easier to place this file in your program folder.
Code cannot exploit any "insider knowledge" of the contents of
ArrayVals.txt file,
other than it being a file of ints.
ArrayTest has getInput() method that reads the ArrayVals.txt file and
passes values
back to main() via a return statement.
ArrayTest has output() method that receives the values and displays a
report of the
lowest, highest, total, count, and average of the numbers by directly
calling the appropriate class methods.
*/
import java.io.*;
public class Ch07Pc11_ArrayTestTEMPLATE
{
public static void main(String[] args)
{
Ch07Pc11_ArrayDataTEMPLATE arrFunc = new
Ch07Pc11_ArrayDataTEMPLATE();
double[] vals ={5,18,6,2,0,8,0,-6,3};
System.out.printf( "Total: %f
"
+" Ave: %f
"
+" Max: %f
"
+" Min: %f
",
arrFunc.getTotal( vals ),
arrFunc.getAverage( vals ),
arrFunc.getHighest( vals ),
arrFunc.getLowest( vals ));
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!