Question

In: Computer Science

• 1. Write a java program using methods to find the information about a account holder...

• 1. Write a java program using methods to find the information about a account holder at bank.

b) Show different functionalities of a bank account (Deposit, Withdrawal, Print)

Solutions

Expert Solution

Solution:

import java.util.Scanner;

class Bank {
    private String accno;
    private String name;
    private long balance;

    Scanner KB = new Scanner(System.in);

    //method to open an account
    void openAccount() {
        System.out.print("Enter Account No: ");
        accno = KB.next();
        System.out.print("Enter Name: ");
        name = KB.next();
        System.out.print("Enter Balance: ");
        balance = KB.nextLong();
    }

    //method to display account details
    void showAccount() {
        System.out.println(accno + "," + name + "," + balance);
    }

    //method to deposit money
    void deposit() {
        long amt;
        System.out.println("Enter Amount U Want to Deposit : ");
        amt = KB.nextLong();
        balance = balance + amt;
    }

    //method to withdraw money
    void withdrawal() {
        long amt;
        System.out.println("Enter Amount U Want to withdraw : ");
        amt = KB.nextLong();
        if (balance >= amt) {
            balance = balance - amt;
        } else {
            System.out.println("Less Balance..Transaction Failed..");
        }
    }

    //method to search an account number
    boolean search(String acn) {
        if (accno.equals(acn)) {
            showAccount();
            return (true);
        }
        return (false);
    }
}

public class ExBank {
    public static void main(String arg[]) {
        Scanner KB = new Scanner(System.in);

        //create initial accounts
        System.out.print("How Many Customer U Want to Input : ");
        int n = KB.nextInt();
        Bank C[] = new Bank[n];
        for (int i = 0; i < C.length; i++) {
            C[i] = new Bank();
            C[i].openAccount();
        }

        //run loop until menu 5 is not pressed
        int ch;
        do {
            System.out.println("Main Menu\n1. Display All\n 2. Search By Account\n 3. Deposit\n 4. Withdrawal\n 5.E xit ");
                System.out.println("Ur Choice :"); ch = KB.nextInt();
                switch (ch) {
                    case 1:
                        for (int i = 0; i < C.length; i++) {
                            C[i].showAccount();
                        }
                        break;

                    case 2:
                        System.out.print("Enter Account No U Want to Search...: ");
                        String acn = KB.next();
                        boolean found = false;
                        for (int i = 0; i < C.length; i++) {
                            found = C[i].search(acn);
                            if (found) {
                                break;
                            }
                        }
                        if (!found) {
                            System.out.println("Search Failed..Account Not Exist..");
                        }
                        break;

                    case 3:
                        System.out.print("Enter Account No : ");
                        acn = KB.next();
                        found = false;
                        for (int i = 0; i < C.length; i++) {
                            found = C[i].search(acn);
                            if (found) {
                                C[i].deposit();
                                break;
                            }
                        }
                        if (!found) {
                            System.out.println("Search Failed..Account Not Exist..");
                        }
                        break;

                    case 4:
                        System.out.print("Enter Account No : ");
                        acn = KB.next();
                        found = false;
                        for (int i = 0; i < C.length; i++) {
                            found = C[i].search(acn);
                            if (found) {
                                C[i].withdrawal();
                                break;
                            }
                        }
                        if (!found) {
                            System.out.println("Search Failed..Account Not Exist..");
                        }
                        break;

                    case 5:
                        System.out.println("Good Bye..");
                        break;
                }
            }
            while (ch != 5);
        }
    }

Please give thumbsup or do comment in case of any query. Thanks.


Related Solutions

• 1. Write a java program using methods to find the information about a account holder...
• 1. Write a java program using methods to find the information about a account holder at bank. d) Perform the functionalities(Deposit, Withdraw and print) until the user selects to stop.
• 1. Write a java program using methods to find the information about a account holder...
• 1. Write a java program using methods to find the information about a account holder at bank. c) For every transaction make sure make use of his account balance.
1. Servlet program to find the information about an account holder at a bank. ( Bank...
1. Servlet program to find the information about an account holder at a bank. ( Bank name= your name ) (I'm using netbeans with glassfish, lecturer mentioned not to use jsp, mostly use CSS, Javascript, html, xml) • Case: a) Have username and password authentication b) Display his Account balance to be RM10000, c) Show different functionalities of a bank account (Deposit, Withdrawal, Print) d) For every transaction make sure make use of his account balance. e) Perform the functionalities(Deposit,...
Methods – Compute Grade Please write a complete Java program, given the following information about (a...
Methods – Compute Grade Please write a complete Java program, given the following information about (a few lines of code in) main: projectAverage = getAverage(”Project”); // returns average of 2 grades testAverage = getAverage(”Test”); // returns average of 2 grades displayGrade(projectAverage, testAverage); // test are 70% & projects 30%
Q1:Write a Java program to find Fibonacci Series using 1) using for loop 2) using while...
Q1:Write a Java program to find Fibonacci Series using 1) using for loop 2) using while loop To Understand what the Fibonacci series is: The Fibonacci sequence is a series of numbers where a number is the sum of the previous two numbers. Starting with 0 and 1, the sequence goes 0, 1, 1, 2, 3, 5, 8, 13, 21, and so on. Q2: Write a Java program to find the Factorial of a number using a while loop. To...
Using Java Write the class RecursiveProbs, with the methods listed below. Write all the methods using...
Using Java Write the class RecursiveProbs, with the methods listed below. Write all the methods using recursion, NOT LOOPS. You may use JDK String Methods like substring() and length(), but do not use the JDK methods to avoid coding algorithms assigned. For example, don’t use String.revers(). public boolean recursiveContains(char c, String s) { if (s.length() == 0) return false; if (s.charAt(s.length() - 1) == c) return true; else return recursiveContains(c, s.substring(0, s.length() - 1)); } public boolean recursiveAllCharactersSame(String s) return...
JAVA PROGRAM: Creates a Bank Account class with one checking account and methods to withdraw and...
JAVA PROGRAM: Creates a Bank Account class with one checking account and methods to withdraw and deposit. Test the methods in the main function.
CIT 149 JAVA 1 program question? Write a program that will use static methods as described...
CIT 149 JAVA 1 program question? Write a program that will use static methods as described in the specifications below. Utilizing the if and else statements, write a program which will calculate a commission based on a two-tiered commission plan of 3% and 7% paid on amounts of $15,000 or less, or over $15,000 in monthly sales by a sales force paid on a commission basis. Use the output specifications below. ? Specifications There will be two classes (separate files)...
Write a Java program using using WHILE loop to find the sum of all integers between...
Write a Java program using using WHILE loop to find the sum of all integers between 200 to 250 which are divisible by 7. Sample Output: Numbers between 200 and 250, divisible by 7: 203 210 217 224 231 238 245 The sum is: 1568
Java - Write a test program that creates an Account object with an account number of...
Java - Write a test program that creates an Account object with an account number of AC1111, a balance of $25,000, and an annual interest rate of 3.5. Use the withdraw method to withdraw $3,500, use the deposit method to deposit $3,500, and print the balance, the monthly interest, and the date when this account was created.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT