[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Java

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 23
Thread images: 5

File: 1483918922984.jpg (36KB, 640x480px) Image search: [Google]
1483918922984.jpg
36KB, 640x480px
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%
>>
File: code.jpg (71KB, 734x489px) Image search: [Google]
code.jpg
71KB, 734x489px
Here's the code and the input.

Currently doesn't return the correct value
>>
can you not just divide by 100? 10/100 = 10%
>>
File: code.jpg (12KB, 127x175px) Image search: [Google]
code.jpg
12KB, 127x175px
>>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*
>>
File: code.jpg (111KB, 582x701px) Image search: [Google]
code.jpg
111KB, 582x701px
>>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
>>
File: code.jpg (16KB, 382x141px) Image search: [Google]
code.jpg
16KB, 382x141px
>>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
>>
>>365929
>>365989
In which case store the empty squares by not putting them in the map at all, and use ContainsKey to see if the square is empty or not.
>>
>>365890
your discord doesnt exist
>>
>>366096
My bad Ducky#9239
Thread posts: 23
Thread images: 5


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.