Question

Hi I was wondering if you could help with code for creating 3 bank accounts using...

Hi I was wondering if you could help with code for creating 3 bank accounts using Array in Java. Accounts for people John, Jeremy, and Justin.The output can show just their name with made up balance in dollars. Please provide a sample code segment that illustrates how to store data in an array for such scenario.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

here is the code---

package bankaccount;
import java.util.Scanner;
import java.util.stream.IntStream;
import java.util.*;
class bankaccount
{
  


public static void main(String args[])

{
  
   String bankaccount[][];
//declaring 2D array for bankaccount
   bankaccount=new String[3][3]; //initialze the array;
   String ch="N";
   Scanner sc=new Scanner(System.in); //scanner class to take the input from the user
   do{
  
   System.out.println("1. add account \n 2. add balance \3. display all bank account \n 4. exit ");
   int choice=sc.nextInt();
   switch(choice)
   {
      
       case 1 : {
                                   Random random = new Random();
                   String generatenumber = String.format("%04d", random.nextInt(10000)); //generate automated account number

                   System.out.println("Enter 1st Account Number ");
                   bankaccount[0][0]=generatenumber; //put bank account number
                   System.out.println("Enter 1st Account Holder Name "); //given format
                   bankaccount[0][1]=sc.next(); //take input name of holder
                   System.out.println("Enter 1st initial Money "); //given format
                   bankaccount[0][2]=sc.next(); //input of money
                                          
System.out.println("Bank Accounts created Successfully... and account number is : "+bankaccount[0][0]); //show the bank account number which auto generates

                   String generatenumber2 = String.format("%04d", random.nextInt(10000)); //generate automated account number
                  
                   System.out.println("Enter 2nd Account Number ");
                   bankaccount[1][0]=generatenumber2;
                   System.out.println("Enter 2nd Account Holder Name "); //given format
                   bankaccount[1][1]=sc.next();
                   System.out.println("Enter 2nd initial Money "); //given format
                   bankaccount[1][2]=sc.next();
                                          
System.out.println("Bank Accounts created Successfully... and account number is : "+bankaccount[1][0]);
                   String generatenumber3 = String.format("%04d", random.nextInt(10000)); //generate automated account number

                   System.out.println("Enter 3rd Account Number ");
                   bankaccount[2][0]=generatenumber3;
                   System.out.println("Enter 3rd Account Holder Name "); //given format
                   bankaccount[2][1]=sc.next();
                   System.out.println("Enter 3rd initial Money "); //given format
                   bankaccount[2][2]=sc.next();
                  
                  
  
                      
System.out.println("Bank Accounts created Successfully... and account number is : "+bankaccount[2][0]);
                  
          
   break;                  
          
       }
      
   case 2 : {

               System.out.println("Enter account holder number : ");
                       String number=sc.next(); //taking input bank number
                       System.out.println("enter money in dollors: ");
                               int money=sc.nextInt(); //take input money
                              
                       for(int i=0;i<3;i++)
                       { for(int j=0;j<3;j++){
                           if(bankaccount[i][j].equals(number.trim())) //find bank number if true then -->>
                           {
                               String moneyall=bankaccount[i][2];
                               int result=Integer.parseInt(moneyall); //change into integer
                               String totalmoney=String.valueOf(result+money); //into string
                              
                               bankaccount[i][2]=totalmoney;
                              
                               System.out.println("MOney added Successfully...now total money is : "+bankaccount[i][2]);
                               break;
                      
                           }
                          
                          
                       }
                      
                       }
                       break; //statement break the statement;
                      

   }
case 3 :
{

for(int i=0;i<3;i++)
{
   for(int j=0;j<3;j++)
   {
       System.out.println(bankaccount[i][j]); //show all bankaccount
                      
   }
  
}

break;
}  
  
   case 4 :{
       System.out.println("Do you want to exit ? Y/N");
       String re=sc.next();
       if(re.equals("Y"))
       {
           ch="Y"; //to exit from the switch statement
   break;
  
       }
       else{
           ch="N";
           break;
          
       }
   }
  
       default : //default is the last case of the switch
   {
   System.out.println("Thank You !");
   }

  
  
      
   }
  
}
while(!ch.equals("Y"));
  
  
  
  
}

}

and the snapshots---

i am done.. hope it will help you !

here i am using 2D array because of some limitation i am not able to do exactly the scenerio of bank ..but you will feel like as bank... Thank You ! hope fully it will be understandable for you

Add a comment
Know the answer?
Add Answer to:
Hi I was wondering if you could help with code for creating 3 bank accounts using...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Hi could you guys help me with this one! thank you and yes I'll rate you...

    Hi could you guys help me with this one! thank you and yes I'll rate you up! thank you Design a class Contact with the data and functionality for one made up contact person ( Don't use actual contact). As data it should store a name, email, and phone. The functions should include getter (accessor) and setter (modifier) functions for each of these data items. Write a small main function that initializes an array of size 10 with: 3 Contact...

  • Hi I was hoping to get some help with my code for this problem. I don't...

    Hi I was hoping to get some help with my code for this problem. I don't know how to correctly read a txt file and the difference between using string and cstring. My code is at the bottom please help thanks. 1. Create the following “data.txt” file. Each record consists of customer's name and their balance: Maria Brown 2100.90 Jeffrey Jackson 200.20 Bernard Smith 223.10 Matthew Davenport 1630.20 Kimberly Macias 19100.90 Amber Daniels 2400.40 The records in the file will...

  • Hi Guys could someone please help with this questions below. I have also attached the template...

    Hi Guys could someone please help with this questions below. I have also attached the template The following trial balance does not balance. Make the necessary adjustments to correctly balance the trial balance and by placing the account balances in the correct debit/credit column. The following corrections and or adjustments need to be made for errors in the trial balance: • A number of account balances have been placed on the wrong side of the trial balance • An amount...

  • You are to write a banking application in c# that keeps track of bank accounts. It will consist of three classes, Account, Bank and BankTest. The Account class is used to represent a savings account i...

    You are to write a banking application in c# that keeps track of bank accounts. It will consist of three classes, Account, Bank and BankTest. The Account class is used to represent a savings account in a bank. The class must have the following instance variables: a String called accountID                       a String called accountName a two-dimensional integer array called deposits (each row represents deposits made in a week). At this point it should not be given any initial value. Each...

  • Hello, I am wondering what the source code for this problem would be. Thank you so...

    Hello, I am wondering what the source code for this problem would be. Thank you so much. You will write a java program using the Eclipse IDE. The program will allow a user to perform one of two options. The user can look up the dates for a given zodiac sign or enter a date and find what sign corresponds to that date. SIGN START DATE END DATE Aries 3/21 4/19 Taurus 4/20 5/20 Gemini 5/21 6/20 Cancer 6/21 7/22...

  • Need some help with this C++ code. Please screenshot the code if possible. Purpose: Demonstrate the...

    Need some help with this C++ code. Please screenshot the code if possible. Purpose: Demonstrate the ability to create and manipulate classes, data members, and member functions. This assignment also aims at creating a C++ project to handle multiple files (one header file and two .cpp files) at the same time. Remember to follow documentation and variable name guidelines. Create a C++ project to implement a simplified banking system. Your bank is small, so it can have a maximum of...

  • Hello. I was wondering if someone else could help me with this assignment. I received expert...

    Hello. I was wondering if someone else could help me with this assignment. I received expert help earlier today but honestly I could not read the handwriting. No offense!! I think we have all become more accustomed to typing rather than writing. Plus, my request is quite lengthy. Essentially, I have an assignment that I need to turn in but I need to ensure what I have thus far is correct. As a part of this assignment, I need to...

  • JAVA... QUESTION 3 IS A CONTINOUS TO Q2 CAN YOU SEND THE CODE SEPARATELY FOR EACH...

    JAVA... QUESTION 3 IS A CONTINOUS TO Q2 CAN YOU SEND THE CODE SEPARATELY FOR EACH Q , I BE SO THANKFUL Q2. Implement a program to store the applicant’s information for a visa office. You need to implement the following: A super class called Applicant, which has the following instance variables: A variable to store first name of type String. A variable to store last name of type String. A variable to store date of birth, should be implemented...

  • I need help with this assignment. It's due Tuesday at 8 AM. Please follow the instructions thorou...

    I need help with this assignment. It's due Tuesday at 8 AM. Please follow the instructions thoroughly as to not use any advanced material we may not have gone over in class. The instructions let you know what all should be used. Thanks! Use only what you have learned in Chapters 1 - 7. Use of "advanced" material, material not in the text, or project does not follow the instructions, will result in a GRADE OF 0% for the project....

  • C++ i want Lab#3 done can u make clear code so I could understand it. Lab#2The...

    C++ i want Lab#3 done can u make clear code so I could understand it. Lab#2The objective of this lab is compare the populations of various cities that lie in between Toledo and Dayton on I-75. Write a program that produces a bar illustrating the populations. The program should read the name of the city and its population from a file. Have the program continue this process until the end of file is reached. For each city, your program should...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT