1 public class Savings extends Account{
2 double minimumBalance;
3
4 Savings(String name, double amount){
5 this.name = name;
6 if (amount > 0){
7 this.balance = amount;
8 } else {
9 System.out.println(" wARNING: You cannot initialize an acount with a negative balance");
10 System.out.println(" wARNING: Balance will be set to 0 instead");
11 this.balance = 0;
12 }
13 this.minimumBalance = 0;
14 }
15
16
17
18 Savings(String name, double amount, double minBalance){
19 this.name = name;
20 if (amount > 0){
21 this.balance = amount;
22 } else {
23 System.out.println(" wARNING: You cannot initialize an acount with a negative balance");
24 System.out.println(" wARNING: Balance will be set to 0 instead");
25 this.balance = 0;
26 }
27 if (minBalance > 0){
28 this.minimumBalance = minBalance;
29 } else {
30 System.out.println(" wARNING: You cannot initialize an acount with a negative minimum balance");
31 System.out.println(" wARNING: Minimum Balance will be set to 0 instead");
32 this.minimumBalance = 0;
33 }
34 }
35
36
37 public void setMinBal(double newBal){
38 minimumBalance = newBal;
39 }
40
41 public double getMinBal(){
42 return minimumBalance;
43 }
44
45 public boolean withdraw(double amount){
46 if (amount > 0 && amount <= balance && ((balance - amount) >= minimumBalance)) {
47 balance = balance - amount;
48 return true;
49 } else if ( amount > balance){
50 System.out.println(" wARNING: You cannot withdraw more than the current balance");
51 System.out.println(" wARNING: Your current balance is "+ this.getBalance());
52 System.out.println(" wARNING: Withdraw canceled");
53 return false;
54 } else if( amount > 0 && ((balance- amount) < minimumBalance)){
55 System.out.println(" wARNING: You cannot have a balance that is less than the required minimum");
56 System.out.println(" wARNING: Your current balance is "+ this.getBalance());
57 System.out.println(" wARNING: Your balance after withdrawal is "+ (this.getBalance() - amount));
58 System.out.println(" wARNING: Your minimum balance is set to "+ this.getMinBal());
59 System.out.println(" wARNING: Withdraw canceled");
60 return false;
61 } else {
62 System.out.println(" wARNING: Incorrect value given as withdrawn amount");
63 System.out.println(" wARNING: Amount requeste for withdraw "+ amount);
64 System.out.println(" wARNING: Withdraw canceled");
65 return false;
66 }
67 }
68
69 public void display(){
70 System.out.println("\n ****** Savings Account Details ****** ");
71 System.out.println(" Name: "+ this.getName());
72 System.out.println(" Current Balance: "+ this.getBalance());
73 System.out.println(" Minimum Balance: "+ this.getMinBal());
74 System.out.println("\t\t\t\t ****** Savings Account Details ******\n ");
75 }
76 }
Generated with
vim2html
Copyright © 2003-2004 by Chip Cuccio
<http://norlug.org/~chipster/finger>