r/javahelp • • May 19 '24

Core Java Banking app

I have to make a banking app(on console) with feature like withdrawal and deposit and account info using core java concepts like loops,threads, exception handling,file I/O etc! Plss help me with what I have to do!

Code is in comments!

0 Upvotes

17 comments sorted by

•

u/AutoModerator May 19 '24

Please ensure that:

  • Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions

  • You include any and all error messages in full

  • You ask clear questions

  • You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.

    Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar

If any of the above points is not met, your post can and will be removed without further warning.

Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.

Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.

Code blocks look like this:

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.

If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.

To potential helpers

Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

4

u/Camel-Kid 18 year old gamer May 19 '24

Divide and conquer is your best friend

1

u/Optimist_Design5444 May 20 '24

Could you give some more tips?

1

u/OffbeatDrizzle May 20 '24

Use IntelliJ

1

u/Optimist_Design5444 May 21 '24

I am using eclipse bro!

2

u/ivanocj May 20 '24

Have you tried asking on chatgpt? I'm pretty sure that it will give you a very nice answer...

1

u/Optimist_Design5444 May 20 '24

Yess I tried but it's not upto the mark!!

8

u/_Atomfinger_ Tech Lead May 19 '24

Simply saying "I have an assignment help plz" isn't really useful. What do you have? What have you tried? What are you stuck at? This sub won't do your assignment for you.

Here's my suggestion: Start by breaking down the work needing to be done and start doing one feature at a time.

1

u/Optimist_Design5444 May 21 '24

package pack1;

import java.util.HashMap; import java.util.Map; import java.util.Scanner;

class BankAccount { private static Map<String, Double> accountBalances = new HashMap<>(); private static Map<String, String> accountPasswords = new HashMap<>(); private String accountNumber;

public BankAccount(String accountNumber, double balance, String password) {
    this.accountNumber = accountNumber;
    accountBalances.put(accountNumber, balance);
    accountPasswords.put(accountNumber, password);
}

public synchronized void deposit(double amount) {
    double balance = accountBalances.getOrDefault(accountNumber, 0.0);
    System.out.println("Depositing: " + amount);
    balance += amount;
    accountBalances.put(accountNumber, balance);
    System.out.println("Deposit successful. New balance: " + balance);
}

public synchronized void withdraw(double amount) {
    double balance = accountBalances.getOrDefault(accountNumber, 0.0);
    if (balance >= amount) {
        System.out.println("Withdrawing: " + amount);
        balance -= amount;
        accountBalances.put(accountNumber, balance);
        System.out.println("Withdrawal successful. New balance: " + balance);
    } else {
        System.out.println("Insufficient funds");
    }
}

public double getBalance() {
    return accountBalances.getOrDefault(123, 120.0);
}

public static boolean authenticate(String accountNumber, String password) {
    return accountPasswords.containsKey(accountNumber) && accountPasswords.get(accountNumber).equals(password);
}

}

public class Main { public static void main(String[] args) { @SuppressWarnings("resource") Scanner scanner = new Scanner(System.in); System.out.print("Enter your name: "); String name = scanner.nextLine(); System.out.print("Enter your account number: "); String accountNumber = scanner.nextLine(); System.out.print("Enter your account password: "); String password = scanner.nextLine(); System.out.println("Welcome, " + name + "! Account number: " + accountNumber);

    BankAccount account = new BankAccount(accountNumber, 0, password);

    Thread depositThread = new Thread(() -> {
        System.out.print("Enter the amount to deposit: ");
        double amount = scanner.nextDouble();
        account.deposit(amount);
    });

    Thread withdrawThread = new Thread(() -> {
        System.out.print("Enter the amount to withdraw: ");
        double amount = scanner.nextDouble();
        account.withdraw(amount);
    });

    depositThread.start();
    withdrawThread.start();
    

    try {
        depositThread.join();
        withdrawThread.join();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    System.out.println("Final balance: " + account.getBalance());
    
}

}

1

u/severoon pro barista May 23 '24

Please format your code properly.

0

u/Jurahhhhh May 20 '24

Make some classes. Use threads for transactions (withdraw/deposit) and you can use a txt file to "store" account balances.

1

u/Optimist_Design5444 May 21 '24

Thanks bruh I am Trying that!

1

u/Optimist_Design5444 May 21 '24

You the only one who gave me tips everybody else is yapping about how I should do it myself(I am trying rn!)

1

u/OffbeatDrizzle May 20 '24

Use threads for transactions

.. wat?

1

u/Jurahhhhh May 20 '24

They said they needs to use threads, file i/o and some other things? Where else would you use them?

1

u/South_Dig_9172 May 19 '24

Okay that’s easy venmo me $2000 first