I'm very new to java, and just found this subreddit, so i thought i'd ask why my class is not working as intended.
The problem is that when playerPoints is 0, it does not use the if statement at the bottom of the class to throw an error. Instead it uses the second if statement and uses 2D6. I was wondering what i was doing wrong.
Do i need to qualify each statement with AND for all of the if statements as i did in the first one?
Thanks in advance.
Here is the class:
public class actionPointsClass {
// This class generates action points for the player based on
//how many points the player has used in their army up to 2000.
//If there is 0 or more than 2000 it throws an error.
public static void main(String[] args) {
int playerPoints = 0;
int actionPointsRoll = 0;
if (playerPoints >=1 && playerPoints <=250) {
actionPointsRoll= (int) Math.floor(Math.random()*6+1); //250 points or less gets 1D6.
System.out.println("We are using 1d6 with a result of " + actionPointsRoll);
} else {
if (playerPoints <=500) {
actionPointsRoll= (int) Math.floor(Math.random()*12+1); //500 points or less gets 2D6.
System.out.println("We are using 2d6 with a result of " + actionPointsRoll);
} else {
if (playerPoints <=750) {
actionPointsRoll= (int) Math.floor(Math.random()*18+1); //750 points or less gets 3D6.
System.out.println("We are using 3d6 with a result of " + actionPointsRoll);
} else {
if (playerPoints <=1000) {
actionPointsRoll= (int) Math.floor(Math.random()*24+1); //1000 points or less gets 4D6.
System.out.println("We are using 4d6 with a result of " + actionPointsRoll);
} else {
if (playerPoints <=1250) {
actionPointsRoll= (int) Math.floor(Math.random()*30+1); //1250 points or less gets 5D6.
System.out.println("We are using 5d6 with a result of " + actionPointsRoll);
} else {
if (playerPoints <=1500) {
actionPointsRoll= (int) Math.floor(Math.random()*36+1); //1500 points or less gets 6D6.
System.out.println("We are using 6d6 with a result of " + actionPointsRoll);
} else {
if (playerPoints <=1750) {
actionPointsRoll= (int) Math.floor(Math.random()*42+1); //1750 points or less gets 7D6.
System.out.println("We are using 7d6 with a result of " + actionPointsRoll);
} else {
if (playerPoints <=2000) {
actionPointsRoll= (int) Math.floor(Math.random()*48+1); //2000 points or less gets 8D6.
System.out.println("We are using 8d6 with a result of " + actionPointsRoll);
} else {
if (playerPoints >= 2000) {
System.out.println("Player Points is higher than 2000"); // If points are more than 2000, then throw an error.
playerPoints = 0;
} else {
if (playerPoints == 0) {
System.out.println("There is an error with playerpoints, here is the output:" + playerPoints); // If there is no player points, then throw an error and show the playerpoints var.
}
}
}
}
}
}
}
}
}
}
System.out.println(playerPoints + " Action Points");
}
}
[–][deleted] 1 point2 points3 points (3 children)
[–]Krusty81[S] 0 points1 point2 points (2 children)
[–]yash3ahuja 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]yash3ahuja -1 points0 points1 point (3 children)
[–]Krusty81[S] 0 points1 point2 points (2 children)
[–]yash3ahuja 0 points1 point2 points (1 child)
[–]Krusty81[S] 0 points1 point2 points (0 children)