Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Program {
- public static void main(String[] args) {
- // Nikki Forehand
- //March 27, 2019
- BankAccount myMoney = new BankAccount(500,9999);
- myMoney.withdraw(10, 99990);
- myMoney.withdraw(-5, 8888);;
- myMoney.withdraw(90, 99990);
- System.out.println(myMoney.getBalance());
- }
- }
- class BankAccount {
- private double balance;
- private int pin;
- public BankAccount(double startingBalance, int newPin) {
- balance = startingBalance;
- pin = newPin;
- }
- public double getBalance() {
- return balance;
- }
- public void withdraw(double amount, int p) {
- if (p==pin) {
- if (amount > 0) {
- balance = balance - amount;
- System.out.println ("Money dispensed. New balance: $" + balance);
- }
- else {
- System.out.println ("Error: Amount must be greater than $0\"");
- }
- }
- else {
- System.out.println ("Error: PIN Incorrect");
- }
- }
- }
Add Comment
Please, Sign In to add comment