From 96aea37503ff83692ef62d3d414c39ae303f7a59 Mon Sep 17 00:00:00 2001 From: TiagoRG <35657250+TiagoRG@users.noreply.github.com> Date: Sat, 18 Feb 2023 14:09:52 +0000 Subject: [PATCH] POO utils package created --- 1ano/2semestre/poo/src/utils/MathTools.java | 7 +++++++ 1ano/2semestre/poo/src/utils/UserInput.java | 21 +++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 1ano/2semestre/poo/src/utils/MathTools.java create mode 100644 1ano/2semestre/poo/src/utils/UserInput.java diff --git a/1ano/2semestre/poo/src/utils/MathTools.java b/1ano/2semestre/poo/src/utils/MathTools.java new file mode 100644 index 0000000..fa7c389 --- /dev/null +++ b/1ano/2semestre/poo/src/utils/MathTools.java @@ -0,0 +1,7 @@ +package utils; + +public class MathTools { + public static double round(double n, int places) { + return (Math.round(n * Math.pow(10, places))) / Math.pow(10, places); + } +} diff --git a/1ano/2semestre/poo/src/utils/UserInput.java b/1ano/2semestre/poo/src/utils/UserInput.java new file mode 100644 index 0000000..6aa8238 --- /dev/null +++ b/1ano/2semestre/poo/src/utils/UserInput.java @@ -0,0 +1,21 @@ +package utils; + +import java.util.Scanner; + +public class UserInput { + public static double getNumberBetween(Scanner sin, double min, double max) { + double input; + do { + input = sin.nextDouble(); + } while (input > max || input < min); + return input; + } + + public static double getPositiveNumber(Scanner sin) { + double input; + do { + input = sin.nextDouble(); + } while (input <= 0); + return input; + } +}