techhipbettruvabetnorabahisbahis forumutaraftarium24eduedusedusedusedusedusedusedueduedu Java Program For Profitable Gamble | Java Programs
Latest :

Java Program For Profitable Gamble | Java Programs

Java code for a profitable gamble, here you can see a detailed java program for a gamble java program.

Create a function that takes in three arguments (prob, prize, pay) and returns true if prob * prize > pay; otherwise return false

To illustrate, profitableGamble(0.2, 50, 9) should yield true, since the net profit is 1 (0.2 * 50 – 9), and 1 > 0.

For this problem, our input requirements are probability of winning (prob), prize and pay. Our expected output would be either true, if it’s profitable or false, if it is not profitable. After this, we decide on the logic and set of statements to be used.

To read the required inputs at runtime, we can use Scanner class in Java. This is very useful to read any primitive datatype input at runtime.

For this, we first have to create an object instantiating it and then invoke the necessary method based on our input type by using the object.

Here, probability of winning (prob) is a deciman value so we use the nextDouble() method and both the pay and prize are integers only so, we call the nextInt() method. This can be done as shown below:

int prize,pay;

Scanner sc=new Scanner(System.in);        //creating object of Scanner class

System.out.println(“Enter probability of winning:”);

double prob=sc.nextDouble();                //reading the probability of winning (prob)

System.out.println(“Enter prize:”);

prize=sc.nextInt();                                   //reading the prize

System.out.println(“Enter pay:”);

pay=sc.nextInt();                                    //reading the pay

After getting all our inputs, we will make a method call for a static method (profitableGamble) by passing all our three inputs as parameters or arguments. This method returns a boolean value true if the gamble is profitable else it returns false.

static boolean profitableGamble(double x,int y,int z )

In this method, we will check whether the product of probability of winning and prize is greater than the pay or not. We do so because, it is a profitable gamble only when, we get more than the amount we spend. So the formula used to determine this would be,

prob*prize > pay       (or)       (prob*prize) – pay > 0

If the above condition satisfies then, it would be a profitable gamble. Hence, we return true. Else, if this condition does not satisfy, it means that the gamble is not profitable. So, we return false.

if(x*y>z)

return true;

return false;

This returned value is displayed on the console screen by the main method by making use of the System.out method called the println() which displays everything and goes to the new line after displaying.

System.out.println(“Is The game (“+prob+”,”+prize+”,”+pay+”) is profitable —>”+profitableGamble(prob,prize,pay));

Output – 1:

Here, prob=0.2, prize=50 and pay=9.

prob*prize > pay i.e., 0.2*50 > 9 –> 10 > 9.

This condition satisfies so, the gamble is profitable. Hence, we return true.

Output – 2:

prob=0.9, prize=1 and pay=2

prob*prize > pay i.e., 0.9*1 > 2 –> 0.9>2

This condition is false so, the gamble is not profitable. Therefore, we return false.

techhipbettruvabetnorabahisbahis forumutaraftarium24eduseduseduseduedusedusedusedusedusedu
x

Check Also

Java Program To Reverse An Array | Programs

Java program to reverse an array – We will discuss the various methods to reverse ...

grandpashabetgrandpashabetgrandpashabethttps://mobilebarhawaii.com/ballettea tropazcasibom girişcasibomhacklinkgrandpashabetbets10onwinonwin girişgrandpashabetholiganbetatakoy escortatakoy escortsisli escortjojobetCasibomtürk pornomavibet girişcratosroyalbetdeneme bonusu veren sitelergrandpashabetonwinligobetgonabetJojobetsahabethttps://www.escortbayanlariz.net/betwoonsahabetcasibomcasibom girişEskişehir escortjojobetbakırköy escortdeneme bonusu veren sitelerhalkali escortgrandpashabet girişholiganbet güncel girişankara escort bayancasino siteleriultrabetgrandpashabet girişholiganbetonwinholiganbetgrandpashabetesenyurt anal escortPadişahbetnakitbahiscasibom girişgrandpashabetİstanbul Escorthttps://www.gvscolombia.com/betebetdeneme bonusu veren sitelerJojobet GirişstarzbetsavoybettingsavoybettingjojobetfixbetBetturkey girişcasibom güncel girişkucukcekmece escortholiganbetimajbetkingroyalmadridbetmatbetmavibetmeritbetmeritkingonwinotobetmeritbetimajbetcasibomsekabetbetvolebetordercasinolevantArtemisbetmadridbetmavibetmeritking girişotobetjojobetholiganbetholiganbet girişonwincasibom girişcasibom girişsahabet girişmadridbetbetturkey girişmarsbahis giriş güncelsahabet güncel giriştipobetistanbul escortscanlı bahisstarzbetultrabetjojobetenbetvbettrromabetcasibom girişcasibomcasibom güncel girişjojobetmegabahisjojobet girişmarsbahiszbahisperabetbakırköy escortdeneme bonusu veren sitelerbetebet güncel girişdumanbetsightcarebilyoneronwinonwinsahabetbets10,bets10 giriş,bets10 güncel giriştipobetmarsbahis,marsbahis güncel giriş , marsbahis giriş,marsbahis adresmarsbahis,marsbahis güncel giriş , marsbahis giriş,marsbahis adressekabetpradabettarafbetmilanobetmilanobetpusulabettempobetpusulabettempobetpusulabetjojobetbets10madridbetBostancı escort Bağcılar escortmatbetjojobet,jojobet girişsekabet girişjojobet,jojobet girişjojobetizmir escortcasibomtipobetjasminbetİstanbul Escortbahis sitelericasibomjojobet girişJojobet Girişankara escortzbahiszbahis girişzbahis güncel girişholiganbetcasibomsonbahisdeneme bonusu veren siteler 2025vaycasinocasinomaxizbahisotobet girişimajbetcasibomvaycasinojojobetbetturkeymarsbahis girişmatbet girişmarsbahisbetturkeybetexperdeneme bonusu veren sitelermariobetwinxbetbetexperbetofficegonebetgrandpashabetgrandpashabet güncelpusulabetpusulabetcasibom girişonwin,onwin giriş,onwin güncel giriş,onwin giriş adresitipobetbetebetmarsbahisultrabetholiganbetjojobetfixbetkulisbetnakitbahispinbahisrestbettipobettrendbetultrabetjojobetholiganbetotobetbetexperpusulabetasyabahisparibahiskulisbettipobetHoliganbet girişfixbetvaycasinojojobet,jojobet girişonwinhttps://sahipleniyorum.com/jojobetjojobet girişultrabetmatbetcasibomcasibom girişmaltepe escortextrabet girişmecidiyeköy escortsekabet girişjojobettipobetbetturkeygonabettipobetcasibom girişmavibetmavibet girişmaltcasinomaltcasino girişmavibet güncelJojobet girişMAVİBETİMAJBETextrabetzbahismarsbahisbahis forumcasibom giriştakipçi hilesivaycasinocashback girişjojobetgonebetjojobetjojobetgüncel girişcasinoroyalcasibom