small changes
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
@@ -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<Double, Double> location, double orientation, String name, double radius, double minRadius)
|
||||
public Worm(Tuple<Double, Double> 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<Double, Double> 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<Double, Double> 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));
|
||||
}
|
||||
|
||||
/**
|
Reference in New Issue
Block a user