Java console banking











up vote
1
down vote

favorite












So I wanted to write a basic console based banking app to practice my skills. It makes use of BigDecimal to ensure accuracy. Here is the MVP I plan to enhance it with all banking features soon. I tried to follow the MVC idea as close as possible, I'm pretty happy with the outcome, although I was questioning myself about some things like how I was creating the new account. As of now it can only accept one user, I plan to add some sort of data persistence like SQLite to practice with. Also there is no check to enforce the user to enter their details when creating an account so those fields can be blank. I will be enhancing this in the near future. Any peer reviews greatly appreciated on how my style could be improved, better way of handling how I did it or anything etc.



Main.java



public class Main
{
public static void main(String args)
{
Prompter prompter = new Prompter();

prompter.greetUser();
do
{
prompter.prompt();
prompter.processPrompt();
} while(!prompter.isFinishedBanking);
}
}


Prompter.java



import java.util.Scanner;

public class Prompter
{
protected boolean isFinishedBanking;
protected boolean areCustomerDetailsCorrect;
private String option;

private Scanner scanner = new Scanner(System.in);
private Account account = new Account();

public void prompt()
{
isFinishedBanking = false;
System.out.print("> ");
option = scanner.nextLine();
}

public void processPrompt()
{
if (option.toLowerCase().equals("exit"))
{
System.out.println("nThank you for banking with JBank, goodbye!");
isFinishedBanking = true;
}

else if (option.toLowerCase().equals("home"))
{
System.out.println();
greetUser();
}

else if (option.toLowerCase().equals("options"))
{
showOptions();
}

else if (option.toLowerCase().equals("open"))
{
if(account.isUserCustomer)
{
System.out.println("Error! you have already opened an account.");
}

else
{
do
{
openAccountPrompt();
System.out.println("nAre these details correct? Y/n");
printCustomerDetails();
prompt();

if (option.toLowerCase().equals("n"))
{
areCustomerDetailsCorrect = false;
}

else
{
areCustomerDetailsCorrect = true;
account.openAccount();
System.out.println("nCongratulations! You have successfully opened a new account.");
}
} while(!areCustomerDetailsCorrect);
}
}

else if (option.toLowerCase().equals("deposit"))
{
if (!account.isUserCustomer)
{
System.out.println("nError! you must open an account before you can use this option.n");
}

else
{
System.out.println("nEnter amount you with to deposit.");
prompt();
account.depositFunds(option);
System.out.println("nSuccess! your new balance is: " + account.getAccountBalance());
}
}

else if (option.toLowerCase().equals("check"))
{
if (!account.isUserCustomer)
{
System.out.println("nError! you must open an account before you can use this option.n");
}
System.out.println();
System.out.println("Your account balance is: " + account.getAccountBalance());
}

else if (option.toLowerCase().equals("withdraw"))
{
if (!account.isUserCustomer)
{
System.out.println("nError! you must open an account before you can use this option.n");
}

else
{
System.out.println("nEnter amount you with to withdraw.");
prompt();

if (account.checkAccountForAvailableFunds(option))
{
System.out.println("nError! you don't have the available funds in your account to complete this transaction. Your available balance is: " + account.getAccountBalance());
}
else
{
account.withdrawFunds(option);
System.out.println("nSuccess! your new balance is: " + account.getAccountBalance());
}
}
}

else
{
System.out.println("nError! I didn't recognize your response, please try again.n");
}
}

public void openAccountPrompt()
{
System.out.println("nnEnter your first name.");
prompt();
account.setCustomerFirstName(option);

System.out.println("nEnter your last name.");
prompt();
account.setCustomerLastName(option);

System.out.println("nEnter your address.");
prompt();
account.setCustomerAddress(option);

System.out.println("nEnter your phone number.");
prompt();
account.setCustomerPhoneNumber(option);

System.out.println("nEnter your email address.");
prompt();
account.setCustomerEmailAddress(option);

System.out.println("nEnter amount to fund your new account.");
prompt();

// If left blank defaults to zero.
if (option.equals(""))
{
option = "0";
}
account.setAccountBalance(option);
}

public void printCustomerDetails()
{
System.out.printf("Name: %s %snAddress: %snTelephone number: %snEmail address: %snBeginning balance: %snn",
account.getCustomerFirstName(), account.getCustomerLastName(),
account.getCustomerAddress(),
account.getCustomerPhoneNumber(),
account.getCustomerEmailAddress(),
account.getAccountBalance());
}

public void greetUser()
{
System.out.println("Welcome to JBank! Type "options" for a list of options, "home" to get back here, or "exit" to exit.n");
}

public void showOptions()
{
System.out.println("nOptions: "open" an account, "deposit" funds, "check" balance, or make a "withdraw"n");
}
}


Account.java



import java.math.BigDecimal;

public class Account
{
public boolean isUserCustomer = false;
private Account customerAccount;
private String customerFirstName;
private String customerLastName;
private String customerAddress;
private String customerPhoneNumber;
private String customerEmailAddress;
private String stringAccountBalance;
private BigDecimal bigDecimalAccountBalance = BigDecimal.ZERO;

public Account()
{

}

public Account(String customerFirstName, String customerLastName, String customerAddress, String customerPhoneNumber, String customerEmailAddress, String stringAccountBalance)
{
this.customerFirstName = customerFirstName;
this.customerLastName = customerLastName;
this.customerAddress = customerAddress;
this.customerPhoneNumber = customerPhoneNumber;
this.customerEmailAddress = customerEmailAddress;
this.stringAccountBalance = stringAccountBalance;
}

public String getCustomerFirstName()
{
return customerFirstName;
}

public void setCustomerFirstName(String customerFirstName)
{
this.customerFirstName = customerFirstName;
}

public String getCustomerLastName()
{
return customerLastName;
}

public void setCustomerLastName(String customerLastName)
{
this.customerLastName = customerLastName;
}

public String getCustomerAddress()
{
return customerAddress;
}

public void setCustomerAddress(String customerAddress)
{
this.customerAddress = customerAddress;
}

public String getCustomerPhoneNumber()
{
return customerPhoneNumber;
}

public void setCustomerPhoneNumber(String customerPhoneNumber)
{
this.customerPhoneNumber = customerPhoneNumber;
}

public String getCustomerEmailAddress()
{
return customerEmailAddress;
}

public void setCustomerEmailAddress(String customerEmailAddress)
{
this.customerEmailAddress = customerEmailAddress;
}

public String getAccountBalance()
{
return bigDecimalAccountBalance.toString();
}

public void setAccountBalance(String stringAccountBalance)
{
this.stringAccountBalance = stringAccountBalance;
bigDecimalAccountBalance = new BigDecimal(stringAccountBalance);
}

public void openAccount()
{
customerAccount = new Account(customerFirstName, customerLastName, customerAddress, customerPhoneNumber, customerEmailAddress, stringAccountBalance);
isUserCustomer = true;
}

public void depositFunds(String stringDepositAmount)
{
BigDecimal bigDecimalDepositAmount = new BigDecimal(stringDepositAmount);
bigDecimalAccountBalance = bigDecimalAccountBalance.add(bigDecimalDepositAmount);
}

public void withdrawFunds(String stringWithdrawAmount)
{
BigDecimal bigDecimalWithdrawAmount = new BigDecimal(stringWithdrawAmount);
bigDecimalAccountBalance = bigDecimalAccountBalance.subtract(bigDecimalWithdrawAmount);
}

public boolean checkAccountForAvailableFunds(String stringWithdrawAmount)
{
boolean isAvailable;
BigDecimal bigDecimalWithdrawAmount = new BigDecimal(stringWithdrawAmount);

// Checks to make sure there are enough funds in the account to make the withdraw.
if (bigDecimalAccountBalance.subtract(bigDecimalWithdrawAmount).compareTo(BigDecimal.ZERO) < 0)
{
isAvailable = true;
}
else
{
isAvailable = false;
}
return isAvailable;
}
}









share|improve this question
















bumped to the homepage by Community 20 hours ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.



















    up vote
    1
    down vote

    favorite












    So I wanted to write a basic console based banking app to practice my skills. It makes use of BigDecimal to ensure accuracy. Here is the MVP I plan to enhance it with all banking features soon. I tried to follow the MVC idea as close as possible, I'm pretty happy with the outcome, although I was questioning myself about some things like how I was creating the new account. As of now it can only accept one user, I plan to add some sort of data persistence like SQLite to practice with. Also there is no check to enforce the user to enter their details when creating an account so those fields can be blank. I will be enhancing this in the near future. Any peer reviews greatly appreciated on how my style could be improved, better way of handling how I did it or anything etc.



    Main.java



    public class Main
    {
    public static void main(String args)
    {
    Prompter prompter = new Prompter();

    prompter.greetUser();
    do
    {
    prompter.prompt();
    prompter.processPrompt();
    } while(!prompter.isFinishedBanking);
    }
    }


    Prompter.java



    import java.util.Scanner;

    public class Prompter
    {
    protected boolean isFinishedBanking;
    protected boolean areCustomerDetailsCorrect;
    private String option;

    private Scanner scanner = new Scanner(System.in);
    private Account account = new Account();

    public void prompt()
    {
    isFinishedBanking = false;
    System.out.print("> ");
    option = scanner.nextLine();
    }

    public void processPrompt()
    {
    if (option.toLowerCase().equals("exit"))
    {
    System.out.println("nThank you for banking with JBank, goodbye!");
    isFinishedBanking = true;
    }

    else if (option.toLowerCase().equals("home"))
    {
    System.out.println();
    greetUser();
    }

    else if (option.toLowerCase().equals("options"))
    {
    showOptions();
    }

    else if (option.toLowerCase().equals("open"))
    {
    if(account.isUserCustomer)
    {
    System.out.println("Error! you have already opened an account.");
    }

    else
    {
    do
    {
    openAccountPrompt();
    System.out.println("nAre these details correct? Y/n");
    printCustomerDetails();
    prompt();

    if (option.toLowerCase().equals("n"))
    {
    areCustomerDetailsCorrect = false;
    }

    else
    {
    areCustomerDetailsCorrect = true;
    account.openAccount();
    System.out.println("nCongratulations! You have successfully opened a new account.");
    }
    } while(!areCustomerDetailsCorrect);
    }
    }

    else if (option.toLowerCase().equals("deposit"))
    {
    if (!account.isUserCustomer)
    {
    System.out.println("nError! you must open an account before you can use this option.n");
    }

    else
    {
    System.out.println("nEnter amount you with to deposit.");
    prompt();
    account.depositFunds(option);
    System.out.println("nSuccess! your new balance is: " + account.getAccountBalance());
    }
    }

    else if (option.toLowerCase().equals("check"))
    {
    if (!account.isUserCustomer)
    {
    System.out.println("nError! you must open an account before you can use this option.n");
    }
    System.out.println();
    System.out.println("Your account balance is: " + account.getAccountBalance());
    }

    else if (option.toLowerCase().equals("withdraw"))
    {
    if (!account.isUserCustomer)
    {
    System.out.println("nError! you must open an account before you can use this option.n");
    }

    else
    {
    System.out.println("nEnter amount you with to withdraw.");
    prompt();

    if (account.checkAccountForAvailableFunds(option))
    {
    System.out.println("nError! you don't have the available funds in your account to complete this transaction. Your available balance is: " + account.getAccountBalance());
    }
    else
    {
    account.withdrawFunds(option);
    System.out.println("nSuccess! your new balance is: " + account.getAccountBalance());
    }
    }
    }

    else
    {
    System.out.println("nError! I didn't recognize your response, please try again.n");
    }
    }

    public void openAccountPrompt()
    {
    System.out.println("nnEnter your first name.");
    prompt();
    account.setCustomerFirstName(option);

    System.out.println("nEnter your last name.");
    prompt();
    account.setCustomerLastName(option);

    System.out.println("nEnter your address.");
    prompt();
    account.setCustomerAddress(option);

    System.out.println("nEnter your phone number.");
    prompt();
    account.setCustomerPhoneNumber(option);

    System.out.println("nEnter your email address.");
    prompt();
    account.setCustomerEmailAddress(option);

    System.out.println("nEnter amount to fund your new account.");
    prompt();

    // If left blank defaults to zero.
    if (option.equals(""))
    {
    option = "0";
    }
    account.setAccountBalance(option);
    }

    public void printCustomerDetails()
    {
    System.out.printf("Name: %s %snAddress: %snTelephone number: %snEmail address: %snBeginning balance: %snn",
    account.getCustomerFirstName(), account.getCustomerLastName(),
    account.getCustomerAddress(),
    account.getCustomerPhoneNumber(),
    account.getCustomerEmailAddress(),
    account.getAccountBalance());
    }

    public void greetUser()
    {
    System.out.println("Welcome to JBank! Type "options" for a list of options, "home" to get back here, or "exit" to exit.n");
    }

    public void showOptions()
    {
    System.out.println("nOptions: "open" an account, "deposit" funds, "check" balance, or make a "withdraw"n");
    }
    }


    Account.java



    import java.math.BigDecimal;

    public class Account
    {
    public boolean isUserCustomer = false;
    private Account customerAccount;
    private String customerFirstName;
    private String customerLastName;
    private String customerAddress;
    private String customerPhoneNumber;
    private String customerEmailAddress;
    private String stringAccountBalance;
    private BigDecimal bigDecimalAccountBalance = BigDecimal.ZERO;

    public Account()
    {

    }

    public Account(String customerFirstName, String customerLastName, String customerAddress, String customerPhoneNumber, String customerEmailAddress, String stringAccountBalance)
    {
    this.customerFirstName = customerFirstName;
    this.customerLastName = customerLastName;
    this.customerAddress = customerAddress;
    this.customerPhoneNumber = customerPhoneNumber;
    this.customerEmailAddress = customerEmailAddress;
    this.stringAccountBalance = stringAccountBalance;
    }

    public String getCustomerFirstName()
    {
    return customerFirstName;
    }

    public void setCustomerFirstName(String customerFirstName)
    {
    this.customerFirstName = customerFirstName;
    }

    public String getCustomerLastName()
    {
    return customerLastName;
    }

    public void setCustomerLastName(String customerLastName)
    {
    this.customerLastName = customerLastName;
    }

    public String getCustomerAddress()
    {
    return customerAddress;
    }

    public void setCustomerAddress(String customerAddress)
    {
    this.customerAddress = customerAddress;
    }

    public String getCustomerPhoneNumber()
    {
    return customerPhoneNumber;
    }

    public void setCustomerPhoneNumber(String customerPhoneNumber)
    {
    this.customerPhoneNumber = customerPhoneNumber;
    }

    public String getCustomerEmailAddress()
    {
    return customerEmailAddress;
    }

    public void setCustomerEmailAddress(String customerEmailAddress)
    {
    this.customerEmailAddress = customerEmailAddress;
    }

    public String getAccountBalance()
    {
    return bigDecimalAccountBalance.toString();
    }

    public void setAccountBalance(String stringAccountBalance)
    {
    this.stringAccountBalance = stringAccountBalance;
    bigDecimalAccountBalance = new BigDecimal(stringAccountBalance);
    }

    public void openAccount()
    {
    customerAccount = new Account(customerFirstName, customerLastName, customerAddress, customerPhoneNumber, customerEmailAddress, stringAccountBalance);
    isUserCustomer = true;
    }

    public void depositFunds(String stringDepositAmount)
    {
    BigDecimal bigDecimalDepositAmount = new BigDecimal(stringDepositAmount);
    bigDecimalAccountBalance = bigDecimalAccountBalance.add(bigDecimalDepositAmount);
    }

    public void withdrawFunds(String stringWithdrawAmount)
    {
    BigDecimal bigDecimalWithdrawAmount = new BigDecimal(stringWithdrawAmount);
    bigDecimalAccountBalance = bigDecimalAccountBalance.subtract(bigDecimalWithdrawAmount);
    }

    public boolean checkAccountForAvailableFunds(String stringWithdrawAmount)
    {
    boolean isAvailable;
    BigDecimal bigDecimalWithdrawAmount = new BigDecimal(stringWithdrawAmount);

    // Checks to make sure there are enough funds in the account to make the withdraw.
    if (bigDecimalAccountBalance.subtract(bigDecimalWithdrawAmount).compareTo(BigDecimal.ZERO) < 0)
    {
    isAvailable = true;
    }
    else
    {
    isAvailable = false;
    }
    return isAvailable;
    }
    }









    share|improve this question
















    bumped to the homepage by Community 20 hours ago


    This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.

















      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      So I wanted to write a basic console based banking app to practice my skills. It makes use of BigDecimal to ensure accuracy. Here is the MVP I plan to enhance it with all banking features soon. I tried to follow the MVC idea as close as possible, I'm pretty happy with the outcome, although I was questioning myself about some things like how I was creating the new account. As of now it can only accept one user, I plan to add some sort of data persistence like SQLite to practice with. Also there is no check to enforce the user to enter their details when creating an account so those fields can be blank. I will be enhancing this in the near future. Any peer reviews greatly appreciated on how my style could be improved, better way of handling how I did it or anything etc.



      Main.java



      public class Main
      {
      public static void main(String args)
      {
      Prompter prompter = new Prompter();

      prompter.greetUser();
      do
      {
      prompter.prompt();
      prompter.processPrompt();
      } while(!prompter.isFinishedBanking);
      }
      }


      Prompter.java



      import java.util.Scanner;

      public class Prompter
      {
      protected boolean isFinishedBanking;
      protected boolean areCustomerDetailsCorrect;
      private String option;

      private Scanner scanner = new Scanner(System.in);
      private Account account = new Account();

      public void prompt()
      {
      isFinishedBanking = false;
      System.out.print("> ");
      option = scanner.nextLine();
      }

      public void processPrompt()
      {
      if (option.toLowerCase().equals("exit"))
      {
      System.out.println("nThank you for banking with JBank, goodbye!");
      isFinishedBanking = true;
      }

      else if (option.toLowerCase().equals("home"))
      {
      System.out.println();
      greetUser();
      }

      else if (option.toLowerCase().equals("options"))
      {
      showOptions();
      }

      else if (option.toLowerCase().equals("open"))
      {
      if(account.isUserCustomer)
      {
      System.out.println("Error! you have already opened an account.");
      }

      else
      {
      do
      {
      openAccountPrompt();
      System.out.println("nAre these details correct? Y/n");
      printCustomerDetails();
      prompt();

      if (option.toLowerCase().equals("n"))
      {
      areCustomerDetailsCorrect = false;
      }

      else
      {
      areCustomerDetailsCorrect = true;
      account.openAccount();
      System.out.println("nCongratulations! You have successfully opened a new account.");
      }
      } while(!areCustomerDetailsCorrect);
      }
      }

      else if (option.toLowerCase().equals("deposit"))
      {
      if (!account.isUserCustomer)
      {
      System.out.println("nError! you must open an account before you can use this option.n");
      }

      else
      {
      System.out.println("nEnter amount you with to deposit.");
      prompt();
      account.depositFunds(option);
      System.out.println("nSuccess! your new balance is: " + account.getAccountBalance());
      }
      }

      else if (option.toLowerCase().equals("check"))
      {
      if (!account.isUserCustomer)
      {
      System.out.println("nError! you must open an account before you can use this option.n");
      }
      System.out.println();
      System.out.println("Your account balance is: " + account.getAccountBalance());
      }

      else if (option.toLowerCase().equals("withdraw"))
      {
      if (!account.isUserCustomer)
      {
      System.out.println("nError! you must open an account before you can use this option.n");
      }

      else
      {
      System.out.println("nEnter amount you with to withdraw.");
      prompt();

      if (account.checkAccountForAvailableFunds(option))
      {
      System.out.println("nError! you don't have the available funds in your account to complete this transaction. Your available balance is: " + account.getAccountBalance());
      }
      else
      {
      account.withdrawFunds(option);
      System.out.println("nSuccess! your new balance is: " + account.getAccountBalance());
      }
      }
      }

      else
      {
      System.out.println("nError! I didn't recognize your response, please try again.n");
      }
      }

      public void openAccountPrompt()
      {
      System.out.println("nnEnter your first name.");
      prompt();
      account.setCustomerFirstName(option);

      System.out.println("nEnter your last name.");
      prompt();
      account.setCustomerLastName(option);

      System.out.println("nEnter your address.");
      prompt();
      account.setCustomerAddress(option);

      System.out.println("nEnter your phone number.");
      prompt();
      account.setCustomerPhoneNumber(option);

      System.out.println("nEnter your email address.");
      prompt();
      account.setCustomerEmailAddress(option);

      System.out.println("nEnter amount to fund your new account.");
      prompt();

      // If left blank defaults to zero.
      if (option.equals(""))
      {
      option = "0";
      }
      account.setAccountBalance(option);
      }

      public void printCustomerDetails()
      {
      System.out.printf("Name: %s %snAddress: %snTelephone number: %snEmail address: %snBeginning balance: %snn",
      account.getCustomerFirstName(), account.getCustomerLastName(),
      account.getCustomerAddress(),
      account.getCustomerPhoneNumber(),
      account.getCustomerEmailAddress(),
      account.getAccountBalance());
      }

      public void greetUser()
      {
      System.out.println("Welcome to JBank! Type "options" for a list of options, "home" to get back here, or "exit" to exit.n");
      }

      public void showOptions()
      {
      System.out.println("nOptions: "open" an account, "deposit" funds, "check" balance, or make a "withdraw"n");
      }
      }


      Account.java



      import java.math.BigDecimal;

      public class Account
      {
      public boolean isUserCustomer = false;
      private Account customerAccount;
      private String customerFirstName;
      private String customerLastName;
      private String customerAddress;
      private String customerPhoneNumber;
      private String customerEmailAddress;
      private String stringAccountBalance;
      private BigDecimal bigDecimalAccountBalance = BigDecimal.ZERO;

      public Account()
      {

      }

      public Account(String customerFirstName, String customerLastName, String customerAddress, String customerPhoneNumber, String customerEmailAddress, String stringAccountBalance)
      {
      this.customerFirstName = customerFirstName;
      this.customerLastName = customerLastName;
      this.customerAddress = customerAddress;
      this.customerPhoneNumber = customerPhoneNumber;
      this.customerEmailAddress = customerEmailAddress;
      this.stringAccountBalance = stringAccountBalance;
      }

      public String getCustomerFirstName()
      {
      return customerFirstName;
      }

      public void setCustomerFirstName(String customerFirstName)
      {
      this.customerFirstName = customerFirstName;
      }

      public String getCustomerLastName()
      {
      return customerLastName;
      }

      public void setCustomerLastName(String customerLastName)
      {
      this.customerLastName = customerLastName;
      }

      public String getCustomerAddress()
      {
      return customerAddress;
      }

      public void setCustomerAddress(String customerAddress)
      {
      this.customerAddress = customerAddress;
      }

      public String getCustomerPhoneNumber()
      {
      return customerPhoneNumber;
      }

      public void setCustomerPhoneNumber(String customerPhoneNumber)
      {
      this.customerPhoneNumber = customerPhoneNumber;
      }

      public String getCustomerEmailAddress()
      {
      return customerEmailAddress;
      }

      public void setCustomerEmailAddress(String customerEmailAddress)
      {
      this.customerEmailAddress = customerEmailAddress;
      }

      public String getAccountBalance()
      {
      return bigDecimalAccountBalance.toString();
      }

      public void setAccountBalance(String stringAccountBalance)
      {
      this.stringAccountBalance = stringAccountBalance;
      bigDecimalAccountBalance = new BigDecimal(stringAccountBalance);
      }

      public void openAccount()
      {
      customerAccount = new Account(customerFirstName, customerLastName, customerAddress, customerPhoneNumber, customerEmailAddress, stringAccountBalance);
      isUserCustomer = true;
      }

      public void depositFunds(String stringDepositAmount)
      {
      BigDecimal bigDecimalDepositAmount = new BigDecimal(stringDepositAmount);
      bigDecimalAccountBalance = bigDecimalAccountBalance.add(bigDecimalDepositAmount);
      }

      public void withdrawFunds(String stringWithdrawAmount)
      {
      BigDecimal bigDecimalWithdrawAmount = new BigDecimal(stringWithdrawAmount);
      bigDecimalAccountBalance = bigDecimalAccountBalance.subtract(bigDecimalWithdrawAmount);
      }

      public boolean checkAccountForAvailableFunds(String stringWithdrawAmount)
      {
      boolean isAvailable;
      BigDecimal bigDecimalWithdrawAmount = new BigDecimal(stringWithdrawAmount);

      // Checks to make sure there are enough funds in the account to make the withdraw.
      if (bigDecimalAccountBalance.subtract(bigDecimalWithdrawAmount).compareTo(BigDecimal.ZERO) < 0)
      {
      isAvailable = true;
      }
      else
      {
      isAvailable = false;
      }
      return isAvailable;
      }
      }









      share|improve this question















      So I wanted to write a basic console based banking app to practice my skills. It makes use of BigDecimal to ensure accuracy. Here is the MVP I plan to enhance it with all banking features soon. I tried to follow the MVC idea as close as possible, I'm pretty happy with the outcome, although I was questioning myself about some things like how I was creating the new account. As of now it can only accept one user, I plan to add some sort of data persistence like SQLite to practice with. Also there is no check to enforce the user to enter their details when creating an account so those fields can be blank. I will be enhancing this in the near future. Any peer reviews greatly appreciated on how my style could be improved, better way of handling how I did it or anything etc.



      Main.java



      public class Main
      {
      public static void main(String args)
      {
      Prompter prompter = new Prompter();

      prompter.greetUser();
      do
      {
      prompter.prompt();
      prompter.processPrompt();
      } while(!prompter.isFinishedBanking);
      }
      }


      Prompter.java



      import java.util.Scanner;

      public class Prompter
      {
      protected boolean isFinishedBanking;
      protected boolean areCustomerDetailsCorrect;
      private String option;

      private Scanner scanner = new Scanner(System.in);
      private Account account = new Account();

      public void prompt()
      {
      isFinishedBanking = false;
      System.out.print("> ");
      option = scanner.nextLine();
      }

      public void processPrompt()
      {
      if (option.toLowerCase().equals("exit"))
      {
      System.out.println("nThank you for banking with JBank, goodbye!");
      isFinishedBanking = true;
      }

      else if (option.toLowerCase().equals("home"))
      {
      System.out.println();
      greetUser();
      }

      else if (option.toLowerCase().equals("options"))
      {
      showOptions();
      }

      else if (option.toLowerCase().equals("open"))
      {
      if(account.isUserCustomer)
      {
      System.out.println("Error! you have already opened an account.");
      }

      else
      {
      do
      {
      openAccountPrompt();
      System.out.println("nAre these details correct? Y/n");
      printCustomerDetails();
      prompt();

      if (option.toLowerCase().equals("n"))
      {
      areCustomerDetailsCorrect = false;
      }

      else
      {
      areCustomerDetailsCorrect = true;
      account.openAccount();
      System.out.println("nCongratulations! You have successfully opened a new account.");
      }
      } while(!areCustomerDetailsCorrect);
      }
      }

      else if (option.toLowerCase().equals("deposit"))
      {
      if (!account.isUserCustomer)
      {
      System.out.println("nError! you must open an account before you can use this option.n");
      }

      else
      {
      System.out.println("nEnter amount you with to deposit.");
      prompt();
      account.depositFunds(option);
      System.out.println("nSuccess! your new balance is: " + account.getAccountBalance());
      }
      }

      else if (option.toLowerCase().equals("check"))
      {
      if (!account.isUserCustomer)
      {
      System.out.println("nError! you must open an account before you can use this option.n");
      }
      System.out.println();
      System.out.println("Your account balance is: " + account.getAccountBalance());
      }

      else if (option.toLowerCase().equals("withdraw"))
      {
      if (!account.isUserCustomer)
      {
      System.out.println("nError! you must open an account before you can use this option.n");
      }

      else
      {
      System.out.println("nEnter amount you with to withdraw.");
      prompt();

      if (account.checkAccountForAvailableFunds(option))
      {
      System.out.println("nError! you don't have the available funds in your account to complete this transaction. Your available balance is: " + account.getAccountBalance());
      }
      else
      {
      account.withdrawFunds(option);
      System.out.println("nSuccess! your new balance is: " + account.getAccountBalance());
      }
      }
      }

      else
      {
      System.out.println("nError! I didn't recognize your response, please try again.n");
      }
      }

      public void openAccountPrompt()
      {
      System.out.println("nnEnter your first name.");
      prompt();
      account.setCustomerFirstName(option);

      System.out.println("nEnter your last name.");
      prompt();
      account.setCustomerLastName(option);

      System.out.println("nEnter your address.");
      prompt();
      account.setCustomerAddress(option);

      System.out.println("nEnter your phone number.");
      prompt();
      account.setCustomerPhoneNumber(option);

      System.out.println("nEnter your email address.");
      prompt();
      account.setCustomerEmailAddress(option);

      System.out.println("nEnter amount to fund your new account.");
      prompt();

      // If left blank defaults to zero.
      if (option.equals(""))
      {
      option = "0";
      }
      account.setAccountBalance(option);
      }

      public void printCustomerDetails()
      {
      System.out.printf("Name: %s %snAddress: %snTelephone number: %snEmail address: %snBeginning balance: %snn",
      account.getCustomerFirstName(), account.getCustomerLastName(),
      account.getCustomerAddress(),
      account.getCustomerPhoneNumber(),
      account.getCustomerEmailAddress(),
      account.getAccountBalance());
      }

      public void greetUser()
      {
      System.out.println("Welcome to JBank! Type "options" for a list of options, "home" to get back here, or "exit" to exit.n");
      }

      public void showOptions()
      {
      System.out.println("nOptions: "open" an account, "deposit" funds, "check" balance, or make a "withdraw"n");
      }
      }


      Account.java



      import java.math.BigDecimal;

      public class Account
      {
      public boolean isUserCustomer = false;
      private Account customerAccount;
      private String customerFirstName;
      private String customerLastName;
      private String customerAddress;
      private String customerPhoneNumber;
      private String customerEmailAddress;
      private String stringAccountBalance;
      private BigDecimal bigDecimalAccountBalance = BigDecimal.ZERO;

      public Account()
      {

      }

      public Account(String customerFirstName, String customerLastName, String customerAddress, String customerPhoneNumber, String customerEmailAddress, String stringAccountBalance)
      {
      this.customerFirstName = customerFirstName;
      this.customerLastName = customerLastName;
      this.customerAddress = customerAddress;
      this.customerPhoneNumber = customerPhoneNumber;
      this.customerEmailAddress = customerEmailAddress;
      this.stringAccountBalance = stringAccountBalance;
      }

      public String getCustomerFirstName()
      {
      return customerFirstName;
      }

      public void setCustomerFirstName(String customerFirstName)
      {
      this.customerFirstName = customerFirstName;
      }

      public String getCustomerLastName()
      {
      return customerLastName;
      }

      public void setCustomerLastName(String customerLastName)
      {
      this.customerLastName = customerLastName;
      }

      public String getCustomerAddress()
      {
      return customerAddress;
      }

      public void setCustomerAddress(String customerAddress)
      {
      this.customerAddress = customerAddress;
      }

      public String getCustomerPhoneNumber()
      {
      return customerPhoneNumber;
      }

      public void setCustomerPhoneNumber(String customerPhoneNumber)
      {
      this.customerPhoneNumber = customerPhoneNumber;
      }

      public String getCustomerEmailAddress()
      {
      return customerEmailAddress;
      }

      public void setCustomerEmailAddress(String customerEmailAddress)
      {
      this.customerEmailAddress = customerEmailAddress;
      }

      public String getAccountBalance()
      {
      return bigDecimalAccountBalance.toString();
      }

      public void setAccountBalance(String stringAccountBalance)
      {
      this.stringAccountBalance = stringAccountBalance;
      bigDecimalAccountBalance = new BigDecimal(stringAccountBalance);
      }

      public void openAccount()
      {
      customerAccount = new Account(customerFirstName, customerLastName, customerAddress, customerPhoneNumber, customerEmailAddress, stringAccountBalance);
      isUserCustomer = true;
      }

      public void depositFunds(String stringDepositAmount)
      {
      BigDecimal bigDecimalDepositAmount = new BigDecimal(stringDepositAmount);
      bigDecimalAccountBalance = bigDecimalAccountBalance.add(bigDecimalDepositAmount);
      }

      public void withdrawFunds(String stringWithdrawAmount)
      {
      BigDecimal bigDecimalWithdrawAmount = new BigDecimal(stringWithdrawAmount);
      bigDecimalAccountBalance = bigDecimalAccountBalance.subtract(bigDecimalWithdrawAmount);
      }

      public boolean checkAccountForAvailableFunds(String stringWithdrawAmount)
      {
      boolean isAvailable;
      BigDecimal bigDecimalWithdrawAmount = new BigDecimal(stringWithdrawAmount);

      // Checks to make sure there are enough funds in the account to make the withdraw.
      if (bigDecimalAccountBalance.subtract(bigDecimalWithdrawAmount).compareTo(BigDecimal.ZERO) < 0)
      {
      isAvailable = true;
      }
      else
      {
      isAvailable = false;
      }
      return isAvailable;
      }
      }






      java algorithm object-oriented






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Sep 22 at 2:32

























      asked Sep 17 at 6:28









      Tyler Cook

      64




      64





      bumped to the homepage by Community 20 hours ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







      bumped to the homepage by Community 20 hours ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          Your Prompter class is quite big, and has several responsibilities: prompting for action, validating input and performing the action. It is very volatile, as any new action requires also updating the prompter. I'd break out the actions to their own classes, implementing an BankingAction interface. The prompter would then contain a list of actions, either through a constructor parameter or registered via a registerAction(BankingAction action) method. When prompting, it'd check this list, dispatch the action to the correct instance and be done with it.






          share|improve this answer





















            Your Answer





            StackExchange.ifUsing("editor", function () {
            return StackExchange.using("mathjaxEditing", function () {
            StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
            StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
            });
            });
            }, "mathjax-editing");

            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "196"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














             

            draft saved


            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f203852%2fjava-console-banking%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            Your Prompter class is quite big, and has several responsibilities: prompting for action, validating input and performing the action. It is very volatile, as any new action requires also updating the prompter. I'd break out the actions to their own classes, implementing an BankingAction interface. The prompter would then contain a list of actions, either through a constructor parameter or registered via a registerAction(BankingAction action) method. When prompting, it'd check this list, dispatch the action to the correct instance and be done with it.






            share|improve this answer

























              up vote
              0
              down vote













              Your Prompter class is quite big, and has several responsibilities: prompting for action, validating input and performing the action. It is very volatile, as any new action requires also updating the prompter. I'd break out the actions to their own classes, implementing an BankingAction interface. The prompter would then contain a list of actions, either through a constructor parameter or registered via a registerAction(BankingAction action) method. When prompting, it'd check this list, dispatch the action to the correct instance and be done with it.






              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                Your Prompter class is quite big, and has several responsibilities: prompting for action, validating input and performing the action. It is very volatile, as any new action requires also updating the prompter. I'd break out the actions to their own classes, implementing an BankingAction interface. The prompter would then contain a list of actions, either through a constructor parameter or registered via a registerAction(BankingAction action) method. When prompting, it'd check this list, dispatch the action to the correct instance and be done with it.






                share|improve this answer












                Your Prompter class is quite big, and has several responsibilities: prompting for action, validating input and performing the action. It is very volatile, as any new action requires also updating the prompter. I'd break out the actions to their own classes, implementing an BankingAction interface. The prompter would then contain a list of actions, either through a constructor parameter or registered via a registerAction(BankingAction action) method. When prompting, it'd check this list, dispatch the action to the correct instance and be done with it.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Sep 22 at 5:16









                TomG

                33116




                33116






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f203852%2fjava-console-banking%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Costa Masnaga

                    Fotorealismo

                    Sidney Franklin