Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 Programming Challenge Starting out with Java Tony Gladdis th 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 ChPcArrayDataTEMPLATE
public double getTotaldouble nums
double total nums;
for int i; i nums.length; i
total numsi;
return total;
public double getAverage double nums
double total nums;
for int i; i nums.length; i
total numsi;
return total nums.length;
public double getHighestdouble nums
double maxNum nums;
for int i; i nums.length; i
if maxNum numsi
maxNum numsi;
return maxNum;
public double getLowestdouble nums
double minNum nums;
for int i; i nums.length; i
if minNum numsi
minNum numsi;
return minNum;
Array Test Template: Input is read from the ArrayVals.txt file
Create the file with the values:
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 ChPcArrayTestTEMPLATE
public static void mainString args
ChPcArrayDataTEMPLATE arrFunc new
ChPcArrayDataTEMPLATE;
double vals ;
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started