Step 1: Edit SumMinMaxArgs.java Download the SumMinMaxArgs.java file, and open it in jGrasp (or a text editor...

70.2K

Verified Solution

Question

Programming

Step 1: Edit SumMinMaxArgs.java

Download the SumMinMaxArgs.java file, and open it in jGrasp (ora text editor of your choice). This program takes a number ofcommand line arguments, parses them as ints, and then displays:

  1. The arithmetic sum of the arguments
  2. The smallest argument
  3. The largest argument

If you're unsure how to pass command-line arguments to a programwith jGrasp, see this tutorial. Example output of this program withthe command-line arguments 1 2 3 4 5 is shown below:

Sum: 15Min: 1Max: 5

Further example output for the command-line arguments 87 23 4291 -4 is shown below:

Sum: 239Min: -4Max: 91

_____________________________

public class SumMinMaxArgs {  private int[] array;  // You will need to write the following:  //  // 1. A constructor that takes a reference to an array,  //  and initializes an instance variable with this  //  array reference  //  // 2. An instance method named sum, which will calculate  //  the sum of the elements in the array. If the array  //  is empty (contains no elements), then this will  //  will return 0. You will need a loop for this.  //  // 3. An instance method named min, which will return  //  whichever element in the array is smallest.  //  You can assume that min will only be called if the  //  array is non-empty (contains at least one element).  //  You will need a loop for this. You may use the  //  Math.min method here (see link below for more)  //  https://www.tutorialspoint.com/java/lang/math_min_int.htm  //  // 4. An instance method named max, which will return  //  whichever element in the array is largest.  //  You can assume that max will only be called if the  //  array is non-empty (contains at least one element).  //  You will need a loop for this. You may use the  //  Math.max method here (see link below for more)  //  https://www.tutorialspoint.com/java/lang/math_min_int.htm  //  // TODO - write your code below  // DO NOT MODIFY parseStrings!  public static int[] parseStrings(String[] strings) {    int[] retval = new int[strings.length];    for (int x = 0; x < strings.length; x++) {      retval[x] = Integer.parseInt(strings[x]);    }    return retval;  }  // DO NOT MODIFY main!  public static void main(String[] args) {    int[] argsAsInts = parseStrings(args);    SumMinMaxArgs obj = new SumMinMaxArgs(argsAsInts);    System.out.println(\"Sum: \" + obj.sum());    System.out.println(\"Min: \" + obj.min());    System.out.println(\"Max: \" + obj.max());  }}

Answer & Explanation Solved by verified expert
3.9 Ratings (385 Votes)
Below is the Java Solution with outputscreenshotCode SumMinMaxArgsjavapublic class    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students