From e0ac1d1958bf8a9d53df37a3cb7cb07f562c5754 Mon Sep 17 00:00:00 2001 From: Arthur Bols Date: Wed, 7 Mar 2018 21:48:28 +0100 Subject: [PATCH] small changes --- OGP1718-Worms/src/Main.java | 3 ++ OGP1718-Worms/src/{ => worms/model}/Worm.java | 42 +++++++++++-------- 2 files changed, 28 insertions(+), 17 deletions(-) rename OGP1718-Worms/src/{ => worms/model}/Worm.java (93%) diff --git a/OGP1718-Worms/src/Main.java b/OGP1718-Worms/src/Main.java index e7ddd65..08d90ba 100644 --- a/OGP1718-Worms/src/Main.java +++ b/OGP1718-Worms/src/Main.java @@ -12,6 +12,9 @@ public class Main { System.out.println(input); System.out.println((int)input);*/ + System.out.println(1/2); + System.out.println(1.0/2.0); + System.out.println(8 + 11 % 2); System.out.println((8 + 11) % 2); } diff --git a/OGP1718-Worms/src/Worm.java b/OGP1718-Worms/src/worms/model/Worm.java similarity index 93% rename from OGP1718-Worms/src/Worm.java rename to OGP1718-Worms/src/worms/model/Worm.java index 85df3ed..beebfa3 100644 --- a/OGP1718-Worms/src/Worm.java +++ b/OGP1718-Worms/src/worms/model/Worm.java @@ -1,3 +1,5 @@ +package worms.model; + import be.kuleuven.cs.som.annotate.*; public class Worm { @@ -37,7 +39,7 @@ public class Worm { /** * this variable contains the minimum value of the radius */ - private final double minRadius; + private final double minimumRadius; /** * this variable contains the mass of the worm @@ -84,21 +86,21 @@ public class Worm { * @param orientation ... * @param name ... * @param radius ... - * @param minRadius ... + * @param minimumRadius ... * @throws IllegalArgumentException ... */ - public Worm(Tuple location, double orientation, String name, double radius, double minRadius) + public Worm(Tuple location, double orientation, String name, double radius, double minimumRadius) throws IllegalArgumentException { setLocation(location); - this.orientation = orientation; + setOrientation(orientation); - if (minRadius < 0) - throw new IllegalArgumentException("minRadius must be larger than 0"); // TODO add decent exception msg + if (!isValidMininmumRadius(minimumRadius)) + throw new IllegalArgumentException("Invalid minimum radius"); // TODO add decent exception msg setRadius(radius); - this.minRadius = minRadius; + this.minimumRadius = minimumRadius; this.points = this.maxPoints; int validName = isValidName(name); @@ -137,7 +139,7 @@ public class Worm { */ private void setLocation(Tuple location) throws IllegalArgumentException { - if (location.equals(null)) + if (location == null || Double.isNaN(location.item1) || Double.isNaN(location.item2)) throw new IllegalArgumentException("Illegal value for location"); // TODO add decent exception msg this.location = location; } @@ -159,8 +161,8 @@ public class Worm { * @post the new orientation of the worm must be equal to the given orientation * |new.getOrientation() == orientation */ - public void setOrientation(double orientation) { - + private void setOrientation(double orientation) { + // TODO nominal checking this.orientation = orientation; } @@ -205,8 +207,8 @@ public class Worm { * |! isValidRadius(radius) */ public void setRadius(double radius) throws IllegalArgumentException { - if (radius < this.minRadius) - throw new IllegalArgumentException("Radius is smaller than " + this.minRadius); + if (radius < this.minimumRadius || Double.isNaN(radius)) + throw new IllegalArgumentException("Invalid radius"); this.radius = radius; setMass(radius); @@ -217,8 +219,12 @@ public class Worm { * the minimum radius of the worm expresses the minimum length * of half of the width of the worm */ - public double getMinRadius() { - return this.minRadius; + public double getMinimumRadius() { + return this.minimumRadius; + } + + private boolean isValidMininmumRadius(double radius) { + return !Double.isNaN(radius) && radius > 0; } /** @@ -303,7 +309,7 @@ public class Worm { * the new name for the worm * @post the new name of the worm is equal to the given name * |new.GetName() == name - * @throws IllegalNameException(validName, name) + * @throws IllegalNameException * the given name is not a valid name for any worm * |! isValidName(name) */ @@ -495,10 +501,12 @@ public class Worm { * @return */ public Tuple jumpStep(double deltaTime) { - + if (Double.isNaN(deltaTime)) { + throw new IllegalArgumentException(); + } return Tuple.create(oldLocation.item1 + this.jumpVelocity * Math.cos(this.orientation) * deltaTime, - oldLocation.item2 + this.jumpVelocity * Math.sin(this.orientation) * deltaTime - (1/2) * G * Math.pow(deltaTime, 2)); + oldLocation.item2 + this.jumpVelocity * Math.sin(this.orientation) * deltaTime - 0.5 * G * Math.pow(deltaTime, 2)); } /**