title: Java Date method?class? joptionpane/output/display objects in arraylist from database?
body: <p>Need some help with case 5 &amp; 7. </p>
  
  <p>5 to display all objects &amp; associated variables = (date/account #/name on 1 line + address next four line + balance on the last line.</p>
  
  <p>I dont know how to nest the methods to do the above / format the output.</p>
  
  <p>This looks like it should but keeps giving me java lang null pointer exception</p>
  
  <pre><code>  if(!db.list.isEmpty())
        { 
          for (int i = 0; i &lt; db.list.size(); i++) 
          { 
          String s = " ";    
          s = "hello  123  "+db.getaccount().getcustomer().getAccountNumber()
              +"\nBalance is: "+db.getaccount().balance;
  
          JTextArea text = new JTextArea(s, 6, 20);
          JScrollPane pane = new JScrollPane(text);
          JOptionPane.showMessageDialog(null, pane,
          "Current Customers List", JOptionPane.INFORMATION_MESSAGE);
          }}break;
  </code></pre>
  
  <p>Any help/advice is really appreciated. Thanks in advance,
  full code below</p>
  
  <pre><code>       package bankaccount;
  
  import javax.swing.JOptionPane;
  import javax.swing.JScrollPane;
  import javax.swing.JTextArea;
  
      public class BankAccountTest 
      {
      public static void main (String[] args)
      {
          Database db = new Database();
          Database deleted = new Database();
          boolean done = false;
          while (!done)
  
          {
              int activity = IO.getInt("Please choose one of the following:"+
               "\n 1 to create new account"+ "\n 2 to delete an account"+
              "\n 3 to withdraw from an account"+"\n 4 to deposit to an account"+
               "\n 5 to list all customers"+"\n 6 to list all deleted customers"+
               "\n 7 to display single account "+"\n 8 to exit this program");
  
          switch(activity)
          {
  
        case 1:
  
        //Create new account
        String LastName = IO.getString("Please type last name: ");
        String FirstName = IO.getString("Please type first name: ");
        Name n = new Name (LastName,FirstName);
  
        //Create address object
        String street = IO.getString("Please type your address: ");
        String city = IO.getString("Please type your city: ");
        String state = IO.getString("Please type your state: ");
        String zipcode = IO.getString("Please type your zipcode: ");
        Address addr = new Address (street,city,state,zipcode);
  
        //Create customer object
        String accno = IO.getString("Please enter the account number: ");
        Customer c = new Customer(n,addr,accno);
              //Create bankaccount object 
       double amt = IO.getDouble("Please type the opening account balance: ");
        BankAccount b = new BankAccount(c, amt);
        db.add(b);
        break;
  
  
        case 2:
  
        // Delete an account / copy account info to deleted database
         String key = IO.getString("Enter account number to delete: ");
             db.search(key); 
           if (db.inlist())
        {
              deleted.add(db.remove(db.getindex()));
        } else 
        {
          IO.notFound();
        }
        break;
  
  
        case 3:
  
        // withdraw from an account
          key = IO.getString("Enter account number to withdraw from: ");
          db.search(key);
         if (db.inlist())
        {
           double amount = IO.getDouble("Enter an amount to withdraw: ");
           db.getaccount().withdraw(amount);
           JOptionPane.showMessageDialog(null, "Current account balance is: "
                                          +db.getaccount().getbalance());
        } else 
           {
               IO.notFound();
           }
        break;  
  
        case 4:
  
        // Deposit to an account
            key = IO.getString("Enter account number to deposit to: ");
          db.search(key);
         if (db.inlist())
        {
           double amount = IO.getDouble("Enter an amount to deposit: ");
           db.getaccount().deposit(amount);
           JOptionPane.showMessageDialog(null, "Current account balance is: "
                                          +db.getaccount().getbalance());
        } else 
           {
               IO.notFound();
           }
        break;  
  
        case 5:
        // Display all current accounts
        if(db.list.isEmpty())
        {
          String s = "The list is empty";
          JTextArea text = new JTextArea(s, 6, 20);
          JScrollPane pane = new JScrollPane(text);
          JOptionPane.showMessageDialog(null, pane,
                      "Current Customers", JOptionPane.INFORMATION_MESSAGE);
        }
  
        for (int i = 0; i &lt; db.list.size(); i++)
        {
         // JOptionPane.showMessageDialog(null, " "+db.list.size()); 
          String s = "These exists in the list: ";
          JTextArea text = new JTextArea(s, 6, 20);
          JScrollPane pane = new JScrollPane(text);
          JOptionPane.showMessageDialog(null, pane,
                      "Current Customers List", JOptionPane.INFORMATION_MESSAGE);
        }
        break;
  
        case 6:
        // Display all deleted accounts    in scroll pane like above
        {
  
        }
  
        case 7:
        // Display single account 
         key = IO.getString("Enter account number show: ");
         db.search(key);
         if (db.inlist())
        {
          JOptionPane.showMessageDialog(null, "Account number is: "
                 +db.getaccount().getcustomer().getAccountNumber()+" Balance is: "
                 +db.getaccount().balance);
        } else 
           {
               IO.notFound();
           }
        break;  
  
        case 8:
  
        // exit program
            done=true;
            break;
  
       default:
       JOptionPane.showMessageDialog(null, "Invalid choice, please choose again ", 
                                      "ERROR",JOptionPane.ERROR_MESSAGE);
          }
         }           
        }
        }
  </code></pre>
  
  <p>classes</p>
  
  <pre><code>package bankaccount;
  
  public class BankAccount 
  {
  Customer cust;
  double balance;
  
  BankAccount (Customer c,double b)     
     {
          cust = c;
       balance = b;
     }
  
   void deposit (double amt)
     {
       balance = balance + amt;
     }
  
   void withdraw (double amt)
     {
       balance = balance - amt;
     }
  
   double getbalance ()
     {
      return balance;
     }
  
   Customer getcustomer ()
     {
      return cust;
     }
      }
  </code></pre>
  
  <p>&amp;</p>
  
  <pre><code>package bankaccount;
  
  public class Customer 
  {
   Name name;
   Address addr;
   String accno;
  
   Customer (Name n, Address addy, String acc)
   {
       name = n;
       addr = addy;
       accno = acc;
   }
  
   Name getname()
   {
       return name;
   }
  
   Address getAddress()
   {
       return addr;
   }
  
   String getAccountNumber()
   {
       return accno;
   }
  
   void changeAccountNumber(String acc)
   {
       accno = acc;
   }
   }   
  </code></pre>
  
  <p>&amp;</p>
  
  <pre><code>package bankaccount;
  
  import java.util.ArrayList;
  
  public class Database 
  {
      int index;
      boolean found;
      ArrayList&lt;BankAccount&gt; list;
      BankAccount acc;
  
  Database()
  {
   list = new ArrayList&lt;BankAccount&gt;();
  }
  
  void add(BankAccount b)
  {
     list.add(b);
  }
  
  BankAccount remove (int i)
  {
      return list.remove(i);
  }
  
   BankAccount getaccount()
  {
      return acc;
  }
  
  ArrayList getlist()
  {
      return list;
  }
  
  int getindex()
  {
      return index;
  }
  
  boolean inlist()
  {
      return found;
  }
  
  void search (String key)
  {
      found = false;
      int i = 0;
      //int.length = list.size();
  
      while (i &lt; list.size() &amp;&amp; !found)
      { BankAccount b = list.get(i);
         if (key.equals(b.getcustomer().accno))
    {
    acc = b; found = true; index = i;
    }
  else
    {
    i++;
    }
      }
  }
  }
  </code></pre>
  
  <p>&amp;</p>
  
  <pre><code>package bankaccount;
  
  public class Address 
  {
   String street;
   String city;
   String state;
   String zipcode;     
  
    Address (String str, String cty, String st, String zip)
   {
       street = str;
       city = cty;
       state = st;
       zipcode = zip;
   }
  
   static String getstreet(String street)
   {
       return street;
   }
  
   public String getcity()
   {
       return city;
   } 
  
   public String getstate()
   {
       return state;
   }
  
   public String getzip()
   {
       return zipcode;
   }
  }
  </code></pre>
  
  <p>&amp;</p>
  
  <pre><code>package bankaccount;
  
  import java.text.DateFormat;
  import java.text.SimpleDateFormat;
  import java.util.Calendar;
  import javax.swing.JOptionPane;
  
  public class IO 
  {       
          DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
          Calendar cal = Calendar.getInstance();
  
       static double getDouble(String s)
       {
            return Double.parseDouble(getString(s));  
       }
       static int getInt(String s)
       {
            return Integer.parseInt(getString(s));    
       }
       static String getString(String s)
       {
            return JOptionPane.showInputDialog(s);
       }
       static void notFound() //Display not found
       {
          JOptionPane.showMessageDialog(null, "Account has not been found, "
                                              + "please try again");
       }      
  
       void date()
       {
           JOptionPane.showMessageDialog(null, "Current date is: ")+dateFormat.format(cal.getTime());
       }
  }
  </code></pre>