Levels Tought:
Elementary,Middle School,High School,College,University,PHD
Teaching Since: | Jul 2017 |
Last Sign in: | 210 Weeks Ago, 2 Days Ago |
Questions Answered: | 15833 |
Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
JAVA PROBLEM
Â
Part I: Written answer questions (20) ( submit a .pdf file)
Answer the following questions using no more thanBank.java
/*
 * Bank.java
 *
 * Created on July 21, 2004, 1:23 AM
 */
public class Bank {
   private Account[] accounts;
   private int size;
   private int capacity;
  Â
   private static final int SAVINGS = 0;
   private static final int CHECKING = 1;  Â
   private static final int SENIOR = 0;
   private static final int ADULT = 1;  Â
   private static final int STUDENT = 2;
   private static final int INIT_CAPACITY = 100;
  Â
   /** Creates a new instance of Bank */
   public Bank() ;
  Â
   /********************************************************************
    * Creates a new account.
    * pre: customer information must be not null and types must be valid
    * post: New account added to bank
    * @param customerName String Account owner's name
    * @param customerAddress String Owner's address
    * @param customerAge int Owner's age (in years)
    * @param customerPhoneNumber String Owner's phone number
    * @param customerType int Owner's type of customer within bank
    * @param typeAccount int Account type (savings or checking)
    * @return String New account number
    */
   public String addAccount(String customerName, String customerAddress,
                            int customerAge, String customerPhoneNumber,
                            int customerType, int typeAccount);
  Â
   /***********************************************************************
    * Make a deposit into account.
    * pre: amount must be a positive integer
    * post: Account's balance increases
    * @param accountNumber String Account's number
    * @param amount double Amount to deposit
    * @return double New balance
    */
   public String makeDeposit(String accountNumber, double amount);
  Â
   /***********************************************************************
    * Make a withdrawal from account.
    * pre: amount must be a positive integer
    * post: Account's balance decreases
    * @param accountNumber String Account's number
    * @param amount double Amount to withdraw
    * @return double New balance
    */  Â
   public String makeWithdrawal(String accountNumber, double amount){
       int index = find(accountNumber);
       accounts[index].withdrawal(amount);
       return Double.toString(accounts[index].getBalance());     Â
   }
   /***********************************************************************
    * Returns account information as a string so it can be displayed
    * @param accountNumber String Account's number
    * @return String Account information as a String object
    */  Â
   public String getAccount(String accountNumber);
  Â
   /***********************************************************************
    * Given an account number tells if the account exists or not
    * @param accountNumber String Account's number
    * @return int TRUE if accountNumber exists in accounts[]. Otherwise, -1.
    */  Â
   private int find(String accountNumber);
 /***********************************************************************
   /** You need to create private method : Allocate to allocate a new array to hold the transactions. */
   private void reallocate()
}
/**
* BankApp.java
*
* Created on July 21, 2004, 1:44 AM
*/
public class BankApp {
   public Bank bank;
 Â
   /** Creates a new instance of BankApp */
   public BankApp() {
       bank = new Bank();
   }
 Â
   /**
    * @param args the command line arguments
    */
   public static void main(String[] args) {
       // TODO code application logic here
       BankApp bankApp = new BankApp();
       BankGUI gui = new BankGUI();
       gui.processCommands(bankApp.bank);
     Â
     Â
   }
 Â
}
 the available space:/*
* BankGUI.java
*
* Created on July 21, 2004, 10:21 AM
*/
import javax.swing.*;
/**************************************************************
* This class is an implementation of PDUserInterface
* that uses JOptionPane to display the menu of command choices.
* @author Rafael
*/
public class BankGUI {
    Â
   /** A reference to the Bank object to be processed.
   Globally available to the command-processing methods.
   */
   private Bank theBank = null;
 Â
   // Methods
   /** Method to display the command choices and process user
   commands.
   pre: The bank exists and has accounts.
   post: Accounts are updated based on user commands.
   @param bank A reference to the Bank
   to be processed.
   */
   public void processCommands(Bank bank) {
       String[] commands = {"Add Account",
       "Deposit",
       "Withdrawal",
       "Check Account",
       "Exit"};
     Â
       theBank = bank;
     Â
       int choice;
       do {
           choice = JOptionPane.showOptionDialog(
           null, // No parent
           "Select action", // Prompt message
           "Bank System", // Window title
           JOptionPane.YES_NO_CANCEL_OPTION, // Option type
           JOptionPane.QUESTION_MESSAGE, // Message type
           null, // Icon
           commands, // List of commands
           commands[commands.length - 1]); // Default choice
           switch (choice) {
               case 0: doAddAccount(); break;
               case 1: doDeposit(); break;
               case 2: doWithdrawal(); break;
               case 3: doCheckAccount(); break;
               case 4: System.exit(0);
           }
       } while (choice < commands.length - 1);
       System.exit(0);
   } Â
 Â
   /** Method to add an account.
   pre: The bank exists and has accounts and customers.
   post: A new account is created
   */
   private void doAddAccount() {
       // Request the name
       String customerName = JOptionPane.showInputDialog(
                             "Enter Customer Name");
       if (customerName == null) {
           return; // Dialog was cancelled.
       }
       // Request the address
       String customerAddress = JOptionPane.showInputDialog(
                                "Enter Customer Address");
       if (customerAddress == null) {
           return; // Dialog was cancelled.
       }
       // Request the age
       String age = JOptionPane.showInputDialog("Enter Customer Age");
       if (age == null) {
           return; // Dialog was cancelled.
       }
       int customerAge = Integer.parseInt(age);
     Â
       // Request the phone number
       String customerPhoneNumber = JOptionPane.showInputDialog(
                                    "Enter Customer Phone Number");
       if (customerPhoneNumber == null) {
           return; // Dialog was cancelled.
       }
     Â
       //Request type of customer
       String[] custType = {"Senior", "Adult", "Student", "Cancel"};
       int choice;
       choice = JOptionPane.showOptionDialog(
       null, // No parent
       "Select customer type", // Prompt message
       "Bank System", // Window title
       JOptionPane.YES_NO_CANCEL_OPTION, // Option type
       JOptionPane.QUESTION_MESSAGE, // Message type
       null, // Icon
       custType, // List of commands
       custType[custType.length - 1]); // Default choice
       if (choice == custType.length - 1){
           return; //Dialog was cancelled.
       }
     Â
       int customerType = choice;
     Â
       //Request type of account
       String[] commands = {"Savings", "Checking", "Cancel"};
     Â
       choice = JOptionPane.showOptionDialog(
       null, // No parent
       "Select account type", // Prompt message
       "Bank System", // Window title
       JOptionPane.YES_NO_CANCEL_OPTION, // Option type
       JOptionPane.QUESTION_MESSAGE, // Message type
       null, // Icon
       commands, // List of commands
       commands[commands.length - 1]); // Default choice
       if (choice == commands.length - 1){
           return; //Dialog was cancelled.
       }
       String theNumber = theBank.addAccount(customerName,
                          customerAddress, customerAge,
                          customerPhoneNumber, customerType, choice);
       String message = null;
       message = "Account " + theNumber + " created.";
       // Display confirmation message.
       JOptionPane.showMessageDialog(null, message);
   }
   /** Method to deposit.
   pre: The bank exists and has accounts.
   post: Balance in accounts increases.
   */
   private void doDeposit() {
       // Request the account number.
       String accountNumber = JOptionPane.showInputDialog(
                              "Enter Account Number");
       if (accountNumber == null) {
           return; // Dialog was cancelled.
       }
       String theAmount = JOptionPane.showInputDialog("Enter Amount");
       if (theAmount == null) {
           return; // Dialog was cancelled.
       }
     Â
       double amount = Double.parseDouble(theAmount);
     Â
       // Look up the name.
       String theBalance = theBank.makeDeposit(accountNumber, amount);
       String message = null;
       if (theBalance != null) { // Name was found.
           message = "Account " + accountNumber + " new balance $" +
                     theBalance;
       } else { // Name was not found.
           message = accountNumber + " does not exist";
       }
       // Display the result.
       JOptionPane.showMessageDialog(null, message);
       }
   /** Method to withdrawal.
   pre: The bank exists and has accounts.
   post: Balance in accounts decreases.
   */
   private void doWithdrawal() {
       // Request the account number.
       String accountNumber = JOptionPane.showInputDialog(
                              "Enter Account Number");
       if (accountNumber == null) {
           return; // Dialog was cancelled.
       }
       String theAmount = JOptionPane.showInputDialog("Enter Amount");
       if (theAmount == null) {
           return; // Dialog was cancelled.
       }
     Â
       double amount = Double.parseDouble(theAmount);
     Â
       // Look up the name.
       String theBalance = theBank.makeWithdrawal(accountNumber, amount);
       String message = null;
       if (theBalance != null) { // Name was found.
           message = "Account " + accountNumber + " new balance $" +
                     theBalance;
       } else { // Name was not found.
           message = accountNumber + " does not exist";
       }
       // Display the result.
       JOptionPane.showMessageDialog(null, message);
       }
 Â
   /** Method to deposit.
   pre: The bank exists and has accounts.
 Â
   */
   private void doCheckAccount() {
       // Request the account number.
       String accountNumber = JOptionPane.showInputDialog(
                              "Enter Account Number");
       if (accountNumber == null) {
           return; // Dialog was cancelled.
       }
       // Look up the number.
       String theAccount = theBank.getAccount(accountNumber);
       String message = null;
       if (theAccount != null) { // Name was found.
           message = theAccount;
       } else { // Name was not found.
           message = accountNumber + " does not exist";
       }
       // Display the result.
       JOptionPane.showMessageDialog(null, message);
       }
}
----------- Â ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly