Riešenia

package sk.upjs.paz.average_calculator;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author skupina B
 *
 */

public class Utils {

        /**
         * Tato metoda vrati priemer
         *
         * @param zoznam Vstupny zoznam doublov
         * @return priemer hdnot v zozname
         */

        public static double average(List<Double> zoznam) {
                if (zoznam == null || zoznam.size() == 0) {
                        throw new EmptyListException();
                }
                double sucet = 0;
                for (Double value : zoznam) {
                        sucet += value;
                }
                return sucet / zoznam.size();
        }

        /**
         *
         * @param array
         * @return
         * @throws ParseFailedException
         */

        public static List<Double> parseNumbers(String[] array) throws ParseFailedException {
                ParseFailedException exception = null;
                List<Double> list = new ArrayList<>();
                for (int i = 0; i < array.length; i++) {
                        try {
                                list.add(Double.parseDouble(array[i]));
                        } catch (NumberFormatException e) {
                                if (exception == null) {
                                        exception = new ParseFailedException();
                                }
                                exception.addToProblems(array[i]);
                        }
                }
                if (exception == null) {
                        return list;
                } else {
                        throw exception;
                }
        }

}

 
package sk.upjs.paz.average_calculator;

import sk.upjs.jpaz2.JPAZUtilities;
import sk.upjs.jpaz2.WinPane;

public class Launcher {

        public static void main(String[] args) {
//              List<Double> list = null;
//              System.out.println(Utils.average(list));
                WinPane wp = new WinPane();

//              String[] array = {"12.4", "tri", "78.6", "3.1415", "dva"};
                try {
                        System.out.println(Utils.parseNumbers(args));
                } catch (ParseFailedException e) {
                        e.printStackTrace();
                        System.err.println(e.getProblems());
                }

                JPAZUtilities.delay(100);
                System.out.println("\n\n===============================");
                System.out.println("Program skoncil");
        }
}
package sk.upjs.paz.average_calculator;

public class EmptyListException extends RuntimeException {

}

 
package sk.upjs.paz.average_calculator;

import java.util.ArrayList;
import java.util.List;

public class ParseFailedException extends Exception {

        private List<String> problems = new ArrayList<>();

        public void addToProblems(String s) {
                problems.add(s);
        }

        public List<String> getProblems() {
                return problems;
        }

        public ParseFailedException() {
                super();
                // TODO Auto-generated constructor stub
        }

        public ParseFailedException(String message, Throwable cause, boolean enableSuppression,
                        boolean writableStackTrace) {
                super(message, cause, enableSuppression, writableStackTrace);
                // TODO Auto-generated constructor stub
        }

        public ParseFailedException(String message, Throwable cause) {
                super(message, cause);
                // TODO Auto-generated constructor stub
        }

        public ParseFailedException(String message) {
                super(message);
                // TODO Auto-generated constructor stub
        }

        public ParseFailedException(Throwable cause) {
                super(cause);
                // TODO Auto-generated constructor stub
        }

}