Module 9 Lab Name________________________ 1. Command Line Args Modify problem # 1 from Lab 8 to accept the values for the key as command line arguments. Your program may assume the arguments given at...

1 answer below »
please see theattached document


Module 9 Lab Name________________________ 1. Command Line Args Modify problem # 1 from Lab 8 to accept the values for the key as command line arguments. Your program may assume the arguments given at the command line are integers. If there are no arguments, print a message. If there is at least one argument, compute and print the average of the arguments. Note that you will need to use the parseInt method of the Integer class to extract integer values from the strings that are passed in. If any non-integer values are passed in, your program will produce an error, which is unavoidable at this point. Test your program in NetBeans using the data for problem # 1 Lab 8 as command line arguments. 2. Exploring Variable Length Parameter Lists The file Parameters.java contains a program to test the variable length method average. Note that average must be a static method since it is called from the static method main. 1. Compile and run the program. 2. Add a call to find the average of a single integer, say 13. Print the result of the call. 3. Add a call with an empty parameter list and print the result. Is the behavior what you expected? 4. 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 (Use a While 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? If not, then why? Edit your program to fix the problem. Do not modify the original while loop. 5. 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. //******************************************************* // 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; } } Here is a sample of what your output may look like: mean1 = 49.333333333333336 and min1 = 37 mean2 = 47.142857142857146 and min2 = 21 mean3 = 13.0 and min3 = 13 Return value of average for an empty parameter list is 0.0 Return value of minimum is 2000000000 Enter a sequence of at most 20 non-negative integers with a negative to signal the end.... 22 44 66 -1 The average of the array elements is 6.6 The minimum is 0 Average of numbers read in is 44.0 Minimum of numbers read in is 22 3. 2D Array Write a class called TwoDArray that has the following behaviors for an array of ints. · getTotal – Accepts a 2-D array as its argument and returns the total of all the values in the array · getAverage – Accepts a 2-D array as its argument and returns the average of all the values in the array · getRowTotal - Accepts a 2-D array as it first argument and an integer as its second argument. The second argument should be the subscript of a row in the array. The method should return the total of the values in the specified row. · getColumnTotal - Accepts a 2-D array as it first argument and an integer as its second argument. The second argument should be the subscript of a column in the array. The method should return the total of the values in the specified column. · getHighestInRow - Accepts a 2-D array as it first argument and an integer as its second argument. The second argument should be the subscript of a row in the array. The method should return the highest value stored in the specified row of the argument array. · getLowestInRow - Accepts a 2-D array as it first argument and an integer as its second argument. The second argument should be the subscript of a row in the array. The method should return the lowest value stored in the specified row of the argument array. · getElementCount - Accepts a 2-D array as its argument and returns the count of how many values are in the array. Your client is included in your download for Module 9. It is called TwoDArrayDemo. Make no changes to TwoDArrayDemo. Test Run Processing the int array. There are 6 elements in the array Total value of elements in the array: 26 Average : 4.333333333333333 Total of row 0 : 12 Total of row 1 : 14 Total of col 0 : 9 Total of col 2 : 13 Highest in row 0 : 9 Highest in row 1 : 7 Lowest in row 0 : 1 Lowest in row 1 : 3
Answered Same DayNov 12, 2021

Answer To: Module 9 Lab Name________________________ 1. Command Line Args Modify problem # 1 from Lab 8 to...

Kshitij answered on Nov 13 2021
126 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here