Results 1 to 12 of 12
  1. #1
    maximumammo is offline Banned
    Join Date
    Apr 2012
    Posts
    13
    Rep Power
    0

    Default new to object oriented programming and arrays

    So I am working on a program and I am terrible with arrays, can anyone help me on the code I have left out and explain why?



    Java Code:
    import java.util.Scanner;
    
    public class AccountManagmentSystem {
    
    	public static void main(String[] args)
        {
            int choice=0;
           
            boolean done=false;
           // Create an array to store 5 Bank Accounts
            int[] bankAccount;
            bankAccount = new int[5];
            
           // Read account number, name of the owner, initial balance
           // create the accounts and store them in the array.
    
    bankAccount[1111] = 1;
    bankAccount[2222] = 2;
    bankAccount[3333] = 3;
    bankAccount[4444] = 4;
    bankAccount[5555] = 5;
    
           // Enter the account number you want to manipulate
           // Find the location of the account in the array
    
    
           do
           {
               // Write the code to display the menu shown
        	   System.out.println("      Welcome, please select one of the following option");
        	   System.out.println(" 1. Make a deposit.");
        	   System.out.println(" 2. Make a withdrawal.");
        	   System.out.println(" 3. Add interest.");
        	   System.out.println(" 4. Account Summary.");
        	   System.out.println(" 5. Change Account.");
        	   System.out.println(" 6. Exit from this program.");
        	   choice = scan.nextInt();
    
               // Get the choice
               switch (choice)
                   {
                    // Write cases 1 - 5
               case 1:
            	   System.out.println(" Enter amount of deposit");
            	   depositAmount = Scanner.nextDouble();
            	   
            	   break;
            	   
               case 2:
            	   System.out.println(" Enter the amount you wish to withdraw");
            	   withdrawAmount = Scanner.nextDouble();
            	   break;
            	   
               case 3:
            	   System.out.println("Enter the interest rate");
            	   rate = scan.nextDouble();
            	   break;
               
               case 4:
            	   System.out.println(toString);
            	   break;
            	   
               case 5:
            	   System.out.println("")
            	   break;
    
               case 6:
                   done = true;
                   break;
    
               default:
                   System.out.println("Invalid option, try again!");
                   break;
                   }
    
           } while (!done); // Keep going until the user says to stop.
         
    
        }
    }
    Last edited by maximumammo; 04-22-2012 at 09:27 PM.

  2. #2
    ojn
    ojn is offline Senior Member
    Join Date
    Sep 2008
    Location
    Stockholm, Sweden
    Posts
    119
    Rep Power
    0

    Default Re: new to object oriented programming and arrays

    Java Code:
    bankAccount[1111] = 1;
    bankAccount[2222] = 2;
    bankAccount[3333] = 3;
    bankAccount[4444] = 4;
    bankAccount[5555] = 5;
    Look at your code – trying to declare values to the array – and compare it to the Java array tutorials. Do you see what you've done wrong?

  3. #3
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default Re: new to object oriented programming and arrays

    Java Code:
    int arr [] = new int [5];
    This array called arr has room for 5 integers. Each element inside the array is accessed by indexing into the array.
    The first element is accessed with 0 and the second with 1 and so on
    Java Code:
    arr[0] = 5;
    arr [1] = 62;

  4. #4
    ojn
    ojn is offline Senior Member
    Join Date
    Sep 2008
    Location
    Stockholm, Sweden
    Posts
    119
    Rep Power
    0

    Default Re: new to object oriented programming and arrays

    So instead of letting the OP figuring that out for himself by checking the tutorial I linked, you decided this is too much for for them and just provide a solution?

  5. #5
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default Re: new to object oriented programming and arrays

    Quote Originally Posted by ojn View Post
    So instead of letting the OP figuring that out for himself by checking the tutorial I linked, you decided this is too much for for them and just provide a solution?
    Did your ego get a slap? The code I provided is generic enough I feel. And probably similar stuff is in the link.

    Finally I was replying on my phone and entering text was a hassle that I had not realised you had posted.

  6. #6
    ojn
    ojn is offline Senior Member
    Join Date
    Sep 2008
    Location
    Stockholm, Sweden
    Posts
    119
    Rep Power
    0

    Default Re: new to object oriented programming and arrays

    Quote Originally Posted by al_Marshy_1981 View Post
    Did your ego get a slap?
    Wow. Nice comeback. If you're 12. And I'd say it's your ego that got a "slap" as it's quite egoistic doing what you did, as it doesn't help the OP at all, just your ego.

    The code I provided is generic enough I feel. And probably similar stuff is in the link.
    Of course they're in the link. It's a frickin' tutorial.

    Finally I was replying on my phone and entering text was a hassle that I had not realised you had posted.
    Whether you read my post or not is 100% irrelevant to the point I was making, which is that if the OP gets everything especially such very basic things as array declaration he'll just come back here time and time again, asking us to do his work for him, instead of linking him to relevant pages where he can figure out this stuff for himself.

  7. #7
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default Re: new to object oriented programming and arrays

    Fair enough I apologize.

  8. #8
    maximumammo is offline Banned
    Join Date
    Apr 2012
    Posts
    13
    Rep Power
    0

    Default Re: new to object oriented programming and arrays

    wow, java help and a show! lol, I say thank you to both of you, for giving me a generic piece of code to build on, as well as a tutorial to look at. This is actually the perfect scenario, where people who comment actually provide constructive feedback that allows me to learn from this. Im sick of crap responses like "its obvious" or "im not going to do it for you". Im not looking for people to do it for me but for advice! Thats why I post questions on this forum, to get feedback from the many respected and knowledgeable people who populate this forum. So again thank you for your help and if I have any more questions I will be sure to ask.

  9. #9
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default Re: new to object oriented programming and arrays

    Its not my style to give free answers u only have to read my responses to most people here to see that. I felt my post was generic enough nd dint agree wit ojn attack. I felt my post gave u a nudge in d right direction without giving d game away so to speak. I felt I explained arrays in my post without going further certainly I could have discussed d memory allocated etc. But I dint want to overwhelm you. I don't think it necessary also to direct to tutorials for every question.nd I certainly did not hand feed u. It takes syntax to explain a concept. I felt I did that.

    I apologized in d end not to derail your thread. Learning is always my first priority in my posts. Nd again I felt u had enough syntax of declaring arrays nd had accessing them confused. So as not to insult u I pointed out how instead of a full blown link to arrays altogether.

    In my opinion its easy to give links nd forget a poster. We are here coz we know code nd I don't see why we can't post code when its generic and helpful. It connects the helper to the student more and should be encouraged.

    I will say one thing though there are certainly times when a person needs a link to the basics but I never ever do this when a person has made a genuine attempt at d code like u did as I feel its not only insulting but also demoralising. And only when d poster is so far away from d concept which u certainly were not I post links.

    Again sorry for derailing ur thread. And I hope you have arrays down now. Of not any questions welcome.

  10. #10
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,728
    Blog Entries
    7
    Rep Power
    21

    Default Re: new to object oriented programming and arrays

    Posting from a cell phone sure is a burden (to write and to read ;-)

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  11. #11
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default Re: new to object oriented programming and arrays

    Not sure if genuine. But yeah think I will stick to computer keyboard from now on.

  12. #12
    maximumammo is offline Banned
    Join Date
    Apr 2012
    Posts
    13
    Rep Power
    0

    Default Re: new to object oriented programming and arrays

    ok so I think I corrected and it is better now but if you have any thoughts here is the new code

    Java Code:
    // Read account number, name of the owner, initial balance
           // create the accounts and store them in the array.
            Account[] Accounts = new Account[5];
            Scanner scan = new Scanner(System.in);
    
        
            System.out.println("\t\t\t Enter Account Information");
            for(int i =0 ; i< Accounts.length ; i++)
            {
                 System.out.print("\nAccount " + i + " number: ");
                 String accountNumber = scan.nextLine();
         	  System.out.print("Account " + i + " name: ");
         	  String Name = scan.nextLine();
                 System.out.print("Account " + i + " initial balence: ");
         	  double ini_Balance = scan.nextDouble();
    
         	  Account r = new Account(accountNumber, Name, ini_Balance);
                 Accounts[i]=r;
    
         	  scan.nextLine();
            }

Similar Threads

  1. help for Object Oriented Programming RMI
    By clapton in forum New To Java
    Replies: 0
    Last Post: 03-20-2012, 07:42 PM
  2. Replies: 2
    Last Post: 02-18-2012, 12:10 AM
  3. Simple Problem with Object-Oriented Programming...
    By CuppaCoffee in forum New To Java
    Replies: 12
    Last Post: 01-04-2012, 11:12 PM
  4. Replies: 1
    Last Post: 08-04-2011, 10:22 AM
  5. Help in object oriented programming .
    By renu in forum New To Java
    Replies: 18
    Last Post: 10-26-2010, 08:57 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •