public class Bank {
/**
* Customer class.
*/
public class Customer {
private String firstName, lastName, street, city, state, zip;
/**
* constructor
* pre: none
* post: A Customer object has been created.
* Customer data has been initialized with parameters.
*/
public Customer(String fName, String lName, String str, String c, String s, String z) {
firstName = fName;
lastName = lName;
street = str;
city = c;
state = s;
zip = z;
}
/**
* Returns a String that represents the Customer object.
* pre: none
* post: A string representing the Account object has
* been returned.
*/
public String toString() {
String custString;
custString = firstName + " " + lastName + "\n";
custString += street + "\n";
custString += city + ", " + state + " " + zip + "\n";
return(custString);
}
}
/**
* Account class
*/
public class Account {
private double balance;
private Customer cust;
/**
* constructor
* pre: none
* post: An account has been created. Balance and
* customer data has been initialized with parameters.
*/
public Account(double bal, String fName, String lName, String str, String city, String st, String zip) {
balance = bal;
cust = new Customer(fName, lName, str, city, st, zip);
}
/**
* Returns the current balance.
* pre: none
* post: The account balance has been returned.
*/
public double getBalance() {
return(balance);
}
/**
* A deposit is made to the account.
* pre: none
* post: The balance has been increased by the amount of the deposit.
*/
public void deposit(double amt) {
balance += amt;
}
/**
* A withdrawal is made from the account if there is enough money.
* pre: none
* post: The balance has been decreased by the amount withdrawn.
*/
public void withdrawal(double amt) {
if (amt <= balance) {
balance -= amt;
} else {
System.out.println("Not enough money in account.");
}
}
/**
* Returns a String that represents the Account object.
* pre: none
* post: A string representing the Account object has
* been returned.
*/
public String toString() {
String accountString;
NumberFormat money = NumberFormat.getCurrencyInstance();
accountString = cust.toString();
accountString += "Current balance is " + money.format(balance);
return(accountString);
}
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
Account munozAccount = new Account(250, "Maria", "Munoz", "110 Glades Road", "Mytown", "FL", "33445");
double data;
NumberFormat money = NumberFormat.getCurrencyInstance();
System.out.println(munozAccount);
System.out.print("Enter deposit amount: ");
data = input.nextDouble();
munozAccount.deposit(data);
System.out.println("Balance is: " + money.format(munozAccount.getBalance()));
System.out.print("Enter withdrawal amount: ");
data = input.nextDouble();
munozAccount.withdrawal(data);
System.out.println("Balance is: " + money.format(munozAccount.getBalance()));
}
}