Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: unknown problems

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    29
    Thanks
    2
    Thanked 7 Times in 7 Posts

    Default unknown problems

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    package bank;
    import java.io.*;
    import java.util.*;


    public class accountList {

    private List accountlists = new LinkedList();

    public void addAccount(bankAccount a1)
    {
    accountlists.add(a1);
    }

    public int searchAccountNumber()
    {
    int max = 1000;

    if(accountlists == null)
    return max;

    for(Iterator iterator = accountlists.iterator(); iterator.hasNext()
    {
    bankAccount a1 = (bankAccount) iterator.next();
    if(a1.getAccNumber() > max)
    max = a1.getAccNumber();
    }
    return max;

    }

    public boolean searchAccountNumber(int acc)
    {

    for(Iterator iterator = accountlists.iterator(); iterator.hasNext()
    {
    bankAccount a1 = (bankAccount) iterator.next();
    if(a1.getAccNumber() == acc)
    return true;
    }
    return false;
    }

    public bankAccount searchAccount(int acc)
    {
    for(Iterator iterator = accountlists.iterator(); iterator.hasNext()
    {
    bankAccount a1 = (bankAccount) iterator.next();
    while(a1.getAccNumber() == acc)
    return a1;
    }
    return null;
    }

    public void display()
    {
    for(Iterator iterator = accountlists.iterator(); iterator.hasNext()
    {
    bankAccount a1 = (bankAccount) iterator.next();
    if(a1.equals(null))
    System.out.println("No any accounts.");
    else
    System.out.println(a1);
    }
    }
    }

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    package bank;

    public class bankAccount {
    private String name;
    private int accountnumber;
    private double balance;
    private transactionsList accountTrans = new transactionsList();

    public bankAccount(String n, int account, double balance)
    {
    name = n;
    this.balance = balance;
    accountnumber = account;
    }

    public String toString()
    {
    String str = accountnumber + " " + name + " " + balance;
    return str;
    }

    public double getBalance()
    {
    return balance;
    }

    public String getName()
    {
    return name;
    }

    public int getAccNumber()
    {
    return accountnumber;
    }

    public void deposit(double a)
    {
    balance += a;
    }

    public void withdrawl(double a)
    {
    balance -= a;

    }

    public void addTrans(transactions t)
    {
    accountTrans.addtransactions(t);
    }

    public void display()
    {
    accountTrans.displayAll();
    }

    }

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    package bank;
    import java.io.*;
    import java.util.*;


    public class Main {
    private static Scanner keyboard = new Scanner(System.in);
    private static accountList alist = new accountList();

    public static void main(String[] args) {
    int choice;
    {
    menu();
    choice = keyboard.nextInt();
    switch(choice)
    {
    case 1: addAccount();
    break;
    case 2: displayAccounts();
    break;
    case 3: login();
    break;
    case 4: System.exit(0);
    }
    }while(choice != 4);

    System.out.println("Thanks for using");
    }

    public static void menu()
    {
    System.out.println("1. Add account.");
    System.out.println("2. Display all accounts.");
    System.out.println("3. Login Accounts.");
    System.out.println("4. Exit System.");
    System.out.print("Pleae enter your choice(1- 4): ");
    }

    public static void submenu()
    {
    System.out.println("1. Deposit.");
    System.out.println("2. Withdrawl.");
    System.out.println("3. Show All transactions.");
    System.out.println("4. LogoutAccount.");
    System.out.print("Pleae enter your choice(1- 4): ");
    }

    public static void addAccount()
    {
    String name;
    Scanner keyboard3 = new Scanner(System.in);
    System.out.print("Please enter your first name: ");
    name = keyboard3.nextLine();

    bankAccount account = new bankAccount(name, alist.searchAccountNumber()+1, 0);
    alist.addAccount(account);
    }

    public static void displayAccounts()
    {
    alist.display();
    }

    public static void login()
    {
    int acc, choice;
    boolean check;
    do
    {
    System.out.print("Please enter you account number: ");
    acc = keyboard.nextInt();

    check = alist.searchAccountNumber(acc);
    if(check != true)
    System.out.println("Unable to locate account.");
    }while(check != true);

    bankAccount account = alist.searchAccount(acc);

    if(account != null)
    {
    do
    {
    System.out.println("Current Balance = " + account.getBalance());
    submenu();
    choice = keyboard.nextInt();
    switch(choice)
    {
    case 1: deposit(account);
    break;
    case 2: withdrawl(account);
    break;
    case 3: showAllTrans(account);
    break;
    case 4: return;
    }
    }while(choice != 4);
    }

    }

    public static void deposit(bankAccount acc)
    {
    double amount;
    System.out.print("Enter the amount: ");
    amount = keyboard.nextDouble();
    acc.deposit(amount);
    transactions t1 = new transactions(acc.getBalance(), amount, "+");
    acc.addTrans(t1);
    }

    public static void withdrawl(bankAccount acc)
    {
    double amount;
    do
    {
    System.out.print("Enter the amount: ");
    amount = keyboard.nextDouble();
    if(acc.getBalance() <= amount)
    System.out.println("Low balance.");
    }while(acc.getBalance() <= amount);

    acc.withdrawl(amount);
    transactions t1 = new transactions(acc.getBalance(), amount, "-");
    acc.addTrans(t1);
    }

    public static void showAllTrans(bankAccount acc)
    {
    acc.display();
    }

    }

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    package bank;
    import java.util.*;


    public class transactions {
    private double balance;
    private double withdrawlordeposit;
    private String plusminus;
    //private String date;

    public transactions(double bal, double wd, String pm)
    {
    balance = bal;
    withdrawlordeposit = wd;
    plusminus = pm;

    }

    public String toString()
    {
    String str = plusminus + withdrawlordeposit + " " + balance;
    return str;
    }
    }

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    package bank;
    import java.util.*;


    public class transactions {
    private double balance;
    private double withdrawlordeposit;
    private String plusminus;
    //private String date;

    public transactions(double bal, double wd, String pm)
    {
    balance = bal;
    withdrawlordeposit = wd;
    plusminus = pm;

    }

    public String toString()
    {
    String str = plusminus + withdrawlordeposit + " " + balance;
    return str;
    }
    }
    //can anybody figure out whats wrong here. Its not a syntax error at all. The program runs but when i tried to add new account and enter the first name which the program will ask for. It just gets stuck at there.
    Don't know whats wrong. Can anyone help. Thanks


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: unknown problems

    I've moved this thread. Please read this: http://www.javaprogrammingforums.com...e-posting.html

    Please also use highlight tags when posting code.

    You're going to have to step through this with a debugger, or at the very least add some print statements, to figure out what your code is actually doing. Recommended reading: http://www.javaprogrammingforums.com...t-println.html
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Member
    Join Date
    Apr 2012
    Posts
    160
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Default Re: unknown problems

    Wrap your code in the code tags [ code=java] [/code]

    It makes reading it much easier for us to help you.

  4. #4
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: unknown problems

    public bankAccount searchAccount(int acc)
    {
    for(Iterator iterator = accountlists.iterator(); iterator.hasNext()
    {
    bankAccount a1 = (bankAccount) iterator.next();
    while(a1.getAccNumber() == acc)
    return a1;
    }
    return null;
    }

    You know that once it returns a1, it exits the method.

    int choice;
    {
    menu();
    choice = keyboard.nextInt();
    switch(choice)
    {
    case 1: addAccount();
    break;
    case 2: displayAccounts();
    break;
    case 3: login();
    break;
    case 4: System.exit(0);
    }
    }while(choice != 4);


    Was that supposed to be a do...while() loop because right now I can't find the do and the while loop will execute the ; while choice != 4 ?
    Last edited by javapenguin; June 4th, 2012 at 12:13 PM.

  5. The Following User Says Thank You to javapenguin For This Useful Post:

    kindk12 (June 5th, 2012)

  6. #5
    Junior Member
    Join Date
    Jun 2012
    Posts
    29
    Thanks
    2
    Thanked 7 Times in 7 Posts

    Default Re: unknown problems

    Hey javapenguin
    Thanks for your help. I really did not notice that I have do missing. Since my IDE didn't show any error so I thought it was something with run time.
    Any way the program works good now. Appreciate your help.

Similar Threads

  1. WHAT IS WRONG??!?!? unknown error
    By ineedhelpasap in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 5th, 2012, 02:07 AM
  2. why a unknown symbol is visible on a jsp page which include another html pages
    By se.anilp in forum JavaServer Pages: JSP & JSTL
    Replies: 4
    Last Post: July 21st, 2011, 10:12 AM
  3. [SOLVED] Unknown Character
    By aussiemcgr in forum Java Theory & Questions
    Replies: 19
    Last Post: September 1st, 2010, 05:22 PM
  4. Replies: 6
    Last Post: May 25th, 2010, 02:15 AM
  5. Vectors - accessing an unknown amount of objects
    By fox in forum Loops & Control Statements
    Replies: 1
    Last Post: May 7th, 2010, 03:54 PM