CS174: OOP - Drills - Array Min Index

Developed by Professor Tralie and Professor Mongan.


Exercise Goals

The goals of this exercise are:
  1. To do proper array indexing
  2. To use loops in concert with arrays
  3. To keep track of multiple auxiliary variables in a loop
  4. To properly define methods
Create a static method getMinIndex takes in an array of doubles and returns the index of the minimum element in the array. You must handle the following two special cases:
  1. If there are ties, it should return the lowest index among the ties
  2. If the array is empty, your program should return 0 without crashing
  3. Enter your Ursinus netid before clicking run. This is not your ID number or your email. For example, my netid is ctralie (non Ursinus students can simply enter their name to get this to run, but they won't get an e-mail record or any form of credit)

    Netid
    Clicking Run below will check your work and, if it passes, will submit your work automatically. You must be connected to the VPN for submission to be successful! You will receive a copy of your code via e-mail, so you'll know that it was submitted if you receive that e-mail!

    ArrayUtils.java

    public class ArrayUtils { // TODO: Add your method here }

    Tester.java

    public class Tester { public static void main(String[] args) { int[] arr0 = {3, 5, 0, 8, 0, 2}; int min0 = ArrayUtils.getMinIndex(arr0); int[] arr1 = {9, -3, 4, -3, 2, 5, 3, 2}; int min1 = ArrayUtils.getMinIndex(arr1); int[] arr2 = {}; int min2 = ArrayUtils.getMinIndex(arr2); System.out.print(min0); System.out.print("."); System.out.print(min1); System.out.print("."); System.out.print(min2); } }
    Tester.main(null);

    Output