Question: PLEASE KEEP IT SIMPLE AND EXPLAIN EACH STEP, DO NOT USE AI . The file Parameters.java contains a program to test the variable length method
PLEASE KEEP IT SIMPLE AND EXPLAIN EACH STEP, DO NOT USE AI The file Parameters.java contains a program to test the variable length method average from Section of the
text. Note that average must be a static method since it is called from the static method main.
Compile and run the program. You must use the source option in your compile command.
Add a call to find the average of a single integer, say Print the result of the call.
c Add a call with an empty parameter list and print the result. Is the behavior what you expected?
Add an interactive part to the program. Ask the user to enter a sequence of at most nonnegative integers. Your
program should have a loop that reads the integers into an array and stops when a negative is entered the negative number
should not be stored Invoke the average method to find the average of the integers in the array send the array as the
parameter Does this work?
Add a method minimum that takes a variable number of integer parameters and returns the minimum of the
parameters. Invoke your method on each of the parameter lists used for the average function. CODE:
Parameters.java
Illustrates the concept of a variable parameter list.
import java.util.Scanner;
public class Parameters
Calls the average and minimum methods with
different numbers of parameters.
public static void mainString args
double mean mean;
mean average;
mean average;
System.out.println mean mean;
System.out.println mean mean;
Returns the average of its parameters.
public static double average int list
double result ;
if listlength
int sum ;
for int num: list
sum num;
result doublesum list.length;
return result;
One interesting application of twodimensional arrays is magic squares. A magic square is a square matrix in which the sum
of every row, every column, and both diagonals is the same. Magic squares have been studied for many years, and there are
some particularly famous magic squares. In this exercise you will write code to determine whether a square is magic.
File Square.java contains the shell for a class that represents a square matrix. It contains headers for a constructor that gives
the size of the square and methods to read values into the square, print the square, find the sum of a given row, find the sum
of a given column, find the sum of the main or other diagonal, and determine whether the square is magic. The read method
is given for you; you will need to write the others. Note that the read method takes a Scanner object as a parameter.
File SquareTest.java contains the shell for a program that reads input for squares from a file named magicData and tells
whether each is a magic square. Following the comments, fill in the remaining code. Note that the main method reads the
size of a square, then after constructing the square of that size, it calls the readSquare method to read the square in The
readSquare method must be sent the Scanner object as a parameter.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
