amount (calculated from the gallons per mile of the car). Write constructors and
toString and equals methods for both classes. Create a main method with a menu
in a third class to test the other two classes.
5. Create a Coin class. It should have a private variable face that can be equal to either
HEADS or TAILS , where the last two are integer constants. It should also contain the
private variable bias , which is the probability that you will get heads after flipping
the coin in the air (for a perfect coin bias=0.5 ). Create a flip method that assigns
a value to the variable face using a random number (e.g., Math.random() )andthe
value of the variable bias . For example, if the random number is smaller than the bias,
then the coin should be heads. Also, create an isHead method that returns true when
the coins is heads. Write a main method that creates a coin, flips it 10000 times, and
then prints the number of heads. Create a setBias method that changes the variable
bias . Use the method to change the bias of the coin and then run the experiment
Write a bank application. The application should give you the following choices.
What do you want to do today?
1. Open account
2. Withdraw money
3. Deposit money
4. Show balance
5. Go home
The first option should open a new bank account. An object of type BankAccount should
be created and added to an array of bank accounts. Set the size of the array to 1000. When
a new bank account is created, the account number should be generated automatically. Use
a static variable to do so. For example, the account number can be the current value of
the static variable, where the static variable should be incremented by one after the bank
account is created. Choice 1 should print the account number. Choices 2-4 should ask for
the account number. A for loop can iterate through the array of bank accounts and find
the bank account with the correct account number. This is the bank account on which
the operation should be performed. All operations should be defined as methods. Make
sure that the withdraw method in the BankAccount class does not allow you to withdraw
more money than you have. The menu should be printed by the menu method in the main
class. Choice 5 should terminate the program. This can be done, for example, by calling
System.exit(0) . This means terminate the program and return error code that signals
normal program termination.
Rewrite the project from Chapter 5 to use an object-oriented design. Create the Die
and DiceCup classes.