Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Project {
- public static void main(String[] args) {
- /*
- * Kendred Thompson
- * 4th Period
- * CS 2
- * Bank Account
- */
- BankAccount myMoney = new BankAccount(500, 9999);
- myMoney.withdraw(10, 9999);
- myMoney.withdraw(-5, 8888);
- myMoney.withdraw(90, 9999);
- myMoney.deposit(10, 9999);
- myMoney.deposit(-5, 8888);
- myMoney.deposit(90, 9999);
- 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; //Ok to withdraw money
- 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");
- }
- }
- public void deposit(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