Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package bankquestion;
- import java.util.Scanner;
- import java.text.NumberFormat;
- public class BankQuestion {
- public static void main(String[] args) {
- Account munozAccount = new Account(250, "Maria", "Munoz", "110 Glades Road", "Mytown", "FL", "33445");
- Scanner input = new Scanner(System.in);
- double data;
- NumberFormat money = NumberFormat.getCurrencyInstance();
- System.out.println(munozAccount);
- System.out.print("Would you like to make changes? (y/n)");
- String answer = input.next();
- if (answer.equals("y")) {
- System.out.print("Enter the street: ");
- String street = input.next();
- System.out.print("Enter the city: ");
- String city = input.next();
- System.out.print("Enter the state ");
- String state = input.next();
- System.out.print("Enter the ZIP code: ");
- String zip = input.next();
- munozAccount.changeAddress(street,city,state,zip);
- 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()));
- }
- }
- ********** Account Class **************
- package bankquestion;
- import java.text.NumberFormat;
- public class Account {
- private double balance;
- private Customer cust;
- 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);
- }
- public double getBalance() {
- return(balance);
- }
- public void deposit(double amt) {
- balance += amt;
- }
- public void changeAddress(String street,String city, String state, String zip) {
- cust.changeStreet(street);
- cust.changeCity(city);
- cust.changeState(state);
- cust.changeZip(zip);
- }
- public void withdrawal(double amt) {
- if (amt <= balance) {
- balance -= amt;
- } else {
- System.out.println("Not enough money in account.");
- }
- }
- public String toString() {
- String accountString;
- NumberFormat money = NumberFormat.getCurrencyInstance();
- accountString = cust.toString();
- accountString += "Current balance is " + money.format(balance);
- return(accountString);
- }
- }
- ******************Customer Class *****************
- package bankquestion;
- public class Customer {
- private String firstName, lastName, street, city, state, zip;
- 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;
- }
- public void changeCity(String theCity) {
- city = theCity;
- }
- public void changeStreet(String theStreet) {
- street = theStreet;
- }
- public void changeState(String theState) {
- state = theState;
- }
- public void changeZip (String theZip) {
- zip = theZip;
- }
- public String toString() {
- String custString;
- custString = firstName + " " + lastName + "\n";
- custString += street + "\n";
- custString += city + ", " + state + " " + zip + "\n";
- return(custString);
- }
- }
Add Comment
Please, Sign In to add comment