I Need help with Java.
You don't have to be a pro, knowledge up to hashmaps is about good enough.
I doubt that with the amount of help I need that it can be done in this thread. So contact through discord would be appreciated. Ducky#9293 (Will pay 30-50 bucks for extensive help)
Either way, for now stuck on
[code]
public void setChance(int ch){
this.chance = ch;
int random = (int) (Math.random()*25 + 10);
if(random >= 25-chance){
System.out.println(chance);
System.out.println(random);
}
}
[/code]
I need to get a percentage based on user input from another class, the input is restricted to 10-25 in that other class. So I need to convert the input to %. So 10=10%
Here's the code and the input.
Currently doesn't return the correct value
can you not just divide by 100? 10/100 = 10%
>>365901
I guess?
However that % is used to place mines in a text based minefield (the user puts in the size of the minefield)
try (int) (Math.random()*16 + 10);
>>365907
Doesn't give the correct percentage.
A friend mentioned to do this
int random = math.random()*100
if(random >= 100-chance){
This is a bomb
}
The ''This is a bomb'' is supposed to be the bomb(s) that are going to be assigned to the playing field according to the % the player put in. But I have no clue on how to do that.
Any help?
>>365911
If bombs are assigned by the input chance, e.g. 10%, then for each tile you'd generate a random number between 0 and 1 and check whether it's less than that probability.
<= 0.1 = bomb
>= 0.1 = not bomb
>>365912
>0.1 = not bomb*
>>365912
Any idea on how to do that?
For context here's the full code.
the Square class keeps track of how many bombs are around the square (0,1,2) and if they have been tested
BombSquare is a subclass of square which represents a square with a bomb.
>>365909
After reading i see what the goal is now
I thought you wanted a random number between 10 and 25 based on initial code.
>>365915
I just gave you an algorithm for setting the field, it's up to you to implement your homework
>>365916
int randomRoll = (int)(Math.random()*100);
if(randomRoll <= chance)
{
//i am a bomb
}
>>365918
Also worth mentioning that if you multiply by 100 the max int you can get after casting is 99
>>365918
Would this work?
Added BombSquare bomb = new BombSquare(); in the field class
and made a (for now) empty add method in the BombSquare subclass.
>>365922
Why are you multiplying by 25 instead of 100?
>>365926
Oh thought that was how you would set a limit. My mistake.
On another note I'm confused on how to check the input of the user.
Considering the field is made, how do I assign values to the Hashmap without making 400 puts?
For example I could do field.get(''F6')
But wouldn't that require making the insane amount of puts?
>>365929
Why are you using a hashmap when the thing you're representing is literally an array?
>>365968
Because it's a requirement for the assignment
>>365890
your discord doesnt exist
>>366096
My bad Ducky#9239