From d4cf6f0bbd7627d7834cf1c9c223042f7da21d06 Mon Sep 17 00:00:00 2001 From: TiagoRG <35657250+TiagoRG@users.noreply.github.com> Date: Mon, 8 May 2023 17:35:21 +0100 Subject: [PATCH] [POO] sum and media added to MathTools --- 1ano/2semestre/poo/src/utils/MathTools.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/1ano/2semestre/poo/src/utils/MathTools.java b/1ano/2semestre/poo/src/utils/MathTools.java index 8744e9b..eeb34e9 100644 --- a/1ano/2semestre/poo/src/utils/MathTools.java +++ b/1ano/2semestre/poo/src/utils/MathTools.java @@ -1,5 +1,6 @@ package utils; +import java.util.List; import java.util.Random; public class MathTools { @@ -20,4 +21,15 @@ public class MathTools { return false; return true; } + + public static double sum(List list) { + double sum = 0; + for (double n : list) + sum += n; + return sum; + } + + public static double media(List list) { + return sum(list) / list.size(); + } }