Thread: Objects and classes

  1. #1
    Registered User
    Join Date
    Feb 2016
    Posts
    2

    Objects and classes

    Can any one please tell me why this stops after I input the amount i want to deposit? Its supposed to display the details after I have deposited/withdrawn money fromt he account.



    Code:
     public class Question3
    {
    
    
        public static void main(String [] args)
    
    
        {
            //double deposit1;
            //double deposit2;
            //double withdraw1;
            //double withdraw2;
            String name = new String();
            String number = new String();
            //String theName;
            //String theNum;
            
            int choice;
            double depositAmount;
            double withdrawAmount;
            int numOfAccounts;
    
    
            System.out.print("How many bank accounts would you like to enter?: ");
            numOfAccounts = EasyScanner.nextInt();
    
    
            BankAccount [] accountList = new BankAccount[numOfAccounts];
            
            
            //accountList[0] = new BankAccount(name, number);
            //accountList[1] = new BankAccount(name, number);
            //accountList[2] = new BankAccount(name, number);
            
            
    
    
    
    
            for(int i =0; i<numOfAccounts; i++)
            {
                System.out.println("");
                System.out.println("Bank Account "+(i+1)+" details: ");
                System.out.print("Name of account holder: ");
                name = EasyScanner.nextString();
                
                System.out.print("Account number: ");
                number = EasyScanner.nextString();
                System.out.println(""); 
                
    
    
            }
            
            //for(int i =0; i<numOfAccounts; i++)
            //{
                
                
                
                //System.out.println("Bank Account "+(i+1));
                //System.out.println("Account number: " +accountList[i].getAccountNumber());
                //System.out.println("Account name: " +accountList[i].getAccountName());
                //System.out.println("Account balance: "+accountList[i].getBalance());
                //System.out.println(""); 
                
            //}
    
    
            System.out.print("Which account would you like to deposit into?:  ");
            choice = EasyScanner.nextInt();
            
    
    
            System.out.print("How much do you want to deposit?:  ");
            depositAmount = EasyScanner.nextDouble();
            if(choice==1)
            {
                
                accountList[0].deposit(depositAmount);
            }
            else if(choice==2)
            {
                accountList[1].deposit(depositAmount);
                
            }
    
    
            for (int i =0; i<numOfAccounts; i++)
            {
                accountList[i]= new BankAccount(name, number);
                
                System.out.println("");
                System.out.println("Bank Account "+(i));
                System.out.println("Account number: " +accountList[i].getAccountNumber());
                System.out.println("Account name: " +accountList[i].getAccountName());
                System.out.println("Account balance: " +accountList[i].getBalance());
                System.out.println("");
    
    
            }
    
    
            System.out.print("Whoch account would you like to withdraw from?:  ");
            choice = EasyScanner.nextInt();
            
    
    
            System.out.print("How much do you want to withdraw?: ");
            withdrawAmount = EasyScanner.nextDouble();
            
            if(choice==1)
            {
                accountList[0].withdraw(withdrawAmount);
            }
            else if(choice==2)
            {
                accountList[1].withdraw(withdrawAmount);
    
    
            }
    
    
            for (int i =0; i<numOfAccounts; i++)
            {
                System.out.println("");
                System.out.println("Bank Account "+(i));
                System.out.println("Account number: " +accountList[i].getAccountNumber());
                System.out.println("Account name: " +accountList[i].getAccountName());
                System.out.println("Account balance: " +accountList[i].getBalance());
                System.out.println("");
    
    
            }
    
    
        }
    }

  2. #2
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    Is this... It this Java?

    *vomits*

  3. #3
    Registered User
    Join Date
    Feb 2016
    Posts
    2
    No need to be rude. If you're not willing to help me then go else where please.
    Last edited by aka_damikerry; 02-07-2016 at 11:17 AM.

  4. #4
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    Quote Originally Posted by aka_damikerry View Post
    No need to be rude. If you're not willing to help me then go else where please.
    You're literally on cboard.cprogramming.com.

    Also, your problem is so common, you should be able to figure out how to read in in console input with Java just by googling. You're not the only one who's had this assignment in the past...

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    This is the C++ programming forum though. So, are you asking for help for a Java program? If so, I will move this thread, but you are better off asking in a forum community that has a focus on Java. If not, then you will need to explain why you posted a Java program.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6

  7. #7
    Registered User
    Join Date
    Jul 2013
    Location
    Germany
    Posts
    499
    You are on a c++ forum, that kind of lack at attention to detail makes me wonder about you.

    I am a Java Developer and if you post to https://jsfiddle.net/ I will help you out.

    What is up with the *vomits* mutantJohn? I love C++ too but Java is what pay my bills

    By the way if you get used to cross posting to solve all your problems and you are wanting to be a programmer. This will only get you through college, just wait until the interview.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Classes and objects
    By Nurlana in forum C++ Programming
    Replies: 3
    Last Post: 10-30-2012, 04:57 PM
  2. classes and objects
    By GoldenBoy in forum C++ Programming
    Replies: 12
    Last Post: 07-08-2010, 07:28 AM
  3. Classes & Objects [c++]
    By salmansalman in forum C++ Programming
    Replies: 6
    Last Post: 05-14-2008, 08:02 AM
  4. classes and objects
    By mixalissen in forum C++ Programming
    Replies: 21
    Last Post: 05-08-2008, 10:18 PM
  5. Classes and objects
    By Drainy in forum C++ Programming
    Replies: 8
    Last Post: 04-03-2005, 11:23 PM