From f12fe5b8d562a730716c5ea60053960becbf753a Mon Sep 17 00:00:00 2001 From: tpariney Date: Wed, 17 Sep 2025 15:23:42 +0200 Subject: [PATCH] Add the battery module --- battery/pom.xml | 78 +++++++++++++++++++ .../m1info/gl/tparineymates/Battery.java | 52 +++++++++++++ .../InsufficientChargeException.java | 9 +++ .../gl/tparineymates/BatteryUnitTest.java | 55 +++++++++++++ pom.xml | 1 + 5 files changed, 195 insertions(+) create mode 100644 battery/pom.xml create mode 100644 battery/src/main/java/fr/ufrst/m1info/gl/tparineymates/Battery.java create mode 100644 battery/src/main/java/fr/ufrst/m1info/gl/tparineymates/InsufficientChargeException.java create mode 100644 battery/src/test/java/fr/ufrst/m1info/gl/tparineymates/BatteryUnitTest.java diff --git a/battery/pom.xml b/battery/pom.xml new file mode 100644 index 0000000..dd2a290 --- /dev/null +++ b/battery/pom.xml @@ -0,0 +1,78 @@ + + + 4.0.0 + + robot-modules + fr.ufrst.m1info.gl.tparineymates + 1.0-SNAPSHOT + + + fr.ufrst.m1info.gl.tparineymates + battery + 1.0-SNAPSHOT + + battery + + http://www.example.com + + + UTF-8 + 1.7 + 1.7 + + + + + junit + junit + 4.11 + test + + + + + + + + + maven-clean-plugin + 3.1.0 + + + + maven-resources-plugin + 3.0.2 + + + maven-compiler-plugin + 3.8.0 + + + maven-surefire-plugin + 2.22.1 + + + maven-jar-plugin + 3.0.2 + + + maven-install-plugin + 2.5.2 + + + maven-deploy-plugin + 2.8.2 + + + + maven-site-plugin + 3.7.1 + + + maven-project-info-reports-plugin + 3.0.0 + + + + + diff --git a/battery/src/main/java/fr/ufrst/m1info/gl/tparineymates/Battery.java b/battery/src/main/java/fr/ufrst/m1info/gl/tparineymates/Battery.java new file mode 100644 index 0000000..d69a725 --- /dev/null +++ b/battery/src/main/java/fr/ufrst/m1info/gl/tparineymates/Battery.java @@ -0,0 +1,52 @@ +package fr.ufrst.m1info.gl.tparineymates; + + +import java.util.Timer; +import java.util.TimerTask; + +public class Battery { + + private final long CHARGE_TOP = 1000; + private float chargeLevel; + + public Battery() { + chargeLevel = 100; + } + + public void charge() { + chargeLevel = chargeFunction(chargeLevel); + } + + private static float chargeFunction(float charge) { + return charge*1.1f + 1; + } + + public void setUp() { + Timer timer = new Timer(); + timer.schedule(new TimerTask() { + @Override + public void run() { + charge(); + } + }, 0, CHARGE_TOP); + } + + public float getChargeLevel(){ + return chargeLevel; + } + + public void use(double energy) throws InsufficientChargeException { + if (chargeLevel < energy) throw new InsufficientChargeException(); + chargeLevel -= energy; + } + + public long timeToSufficientCharge(double neededEnergy) { + int clock = 0; + float charge = chargeLevel; + while (charge robot + battery -- GitLab