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 7.5 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 1.5 option in your compile command.
Add a call to find the average of a single integer, say 13. 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 20 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 main(String[] args)
{
double mean1, mean2;
mean1= average(42,69,37);
mean2= average(35,43,93,23,40,21,75);
System.out.println ("mean1="+ mean1);
System.out.println ("mean2="+ mean2);
}
//----------------------------------------------
// Returns the average of its parameters.
//----------------------------------------------
public static double average (int ... list)
{
double result =0.0;
if (list.length !=0)
{
int sum =0;
for (int num: list)
sum += num;
result =(double)sum / list.length;
}
return result;
}
}One interesting application of two-dimensional 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 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 Programming Questions!