In this exercise you will use if and else statements to write some code that simulates a gambler who makes various wagers. As part of your solution, you will use the following parameters that are passed in to the method: A double variable with the identifier money that indicates how much money the gambler has. A double variable with the identifier wager that indicates how much money is being wagered in a particular bet. A Boolean variable with the identifier outcome that indicates if the gambler wins (true) or loses (false) 1) In some cases the gambler is unable to fix the outcome of the wager ahead of time and must rely on luck. Use an if statement to check if outcome has a value (whether or not it is null) If it does not have a value, you will need to assign it one by instantiating a Random object and using one of its methods. 2) Use an if/else statement to determine if the gambler has won the wager (outcome is true) If the gambler has won the wager, add the wager to amount of money the gambler has and Call the println method and print the following: "I've won a $wager wager and now have $money!" where $wager and $money are the values of the wager and how much money the gambler now has respectively. If the gambler has lost the wager, subtract the wager from the amount of money the gambler has and Call the println method and print the following: "I've lost a $wager wager and now have $money!" where $wager and $money are the values of the wager and how much money the gambler now has respectively. 3) Because our gambler is a person of refinement, it would be uncouth not to have properly formatted output You should create a currency instance of the NumberFormat class (US Locale) and use that to format any currency amounts 4) Occasionally our gambler might bite off more than they can chew and run out of money. Use an if statement to check if the gambler still has any money. If the gambler has no money left, call the println method and print the following: "Drats! I've gone bust." */ public static Object[] question2(double money, double wager, Boolean outcome) { // Your code goes here:

Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter9: Advanced Modularization Techniques
Section: Chapter Questions
Problem 9PE
icon
Related questions
Question

In this exercise you will use if and else statements to write some code that simulates a gambler who makes various wagers.
As part of your solution, you will use the following parameters that are passed in to the method:
A double variable with the identifier money that indicates how much money the gambler has.
A double variable with the identifier wager that indicates how much money is being wagered in a particular bet.
A Boolean variable with the identifier outcome that indicates if the gambler wins (true) or loses (false)

1) In some cases the gambler is unable to fix the outcome of the wager ahead of time and must rely on luck.
Use an if statement to check if outcome has a value (whether or not it is null)
If it does not have a value, you will need to assign it one by instantiating a Random object
and using one of its methods.

2) Use an if/else statement to determine if the gambler has won the wager (outcome is true)
If the gambler has won the wager, add the wager to amount of money the gambler has and
Call the println method and print the following:
"I've won a $wager wager and now have $money!"
where $wager and $money are the values of the wager and how much money the gambler now has respectively.

If the gambler has lost the wager, subtract the wager from the amount of money the gambler has and
Call the println method and print the following:
"I've lost a $wager wager and now have $money!"
where $wager and $money are the values of the wager and how much money the gambler now has respectively.

3) Because our gambler is a person of refinement, it would be uncouth not to have properly formatted output
You should create a currency instance of the NumberFormat class (US Locale) and use that to format any currency amounts

4) Occasionally our gambler might bite off more than they can chew and run out of money.
Use an if statement to check if the gambler still has any money.
If the gambler has no money left, call the println method and print the following:
"Drats! I've gone bust."

*/
public static Object[] question2(double money, double wager, Boolean outcome)
{
// Your code goes here:


// Necessary for unit test. Do not remove!
return new Object[] {money, outcome};
}

public static void main(String[] args)
{
// Example input to test method
question2(100, 50, true);
}
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Returning value from Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT