Advertisement
Guest User

java project

a guest
Jan 10th, 2025
726
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 10.36 KB | Source Code | 0 0
  1. import java.util.*;
  2. class BankManagement{
  3.     public static void main(String[] args){
  4.         Scanner sc = new Scanner(System.in);
  5.         String accountname = null;
  6.         String password = null;
  7.         boolean accountcreated = false;
  8.         double balance = 0.0;
  9.         double wallet = 300.0;
  10.         System.out.println("Welcome to the bank! What would you like to do?");
  11.         while (true) {
  12.             System.out.println("1. Create an account");
  13.             System.out.println("2. Deposit or withdraw money");
  14.             System.out.println("3. Edit account details");
  15.             System.out.println("4. Check balance");
  16.             System.out.println("5. Exit");
  17.             int choice = sc.nextInt();
  18.             sc.nextLine();
  19.  
  20.             switch (choice) {
  21.                 case 1:
  22.                     if (accountcreated == true) {
  23.                         System.out.println("An account is already created.");
  24.                     } else {
  25.                         System.out.println("What would you like to name your account?");
  26.                         accountname = sc.nextLine();
  27.                         System.out.println("Great " + accountname + ", now set a password.");
  28.                         password = sc.nextLine();
  29.                         System.out.println("Your name is " + accountname + ", and your password is " + password + ". Press 1 to confirm account creation, 2 to cancel.");
  30.                         int confirm = sc.nextInt();
  31.                         if (confirm == 1) {
  32.                             System.out.println("Account has been created.");
  33.                             accountcreated = true;
  34.                         } else if (confirm == 2) {
  35.                             System.out.println("Going back to the menu.");
  36.                              accountname = null;
  37.                              password = null;
  38.                              accountcreated = false;
  39.  
  40.                         } else {
  41.                             System.out.println("Error");
  42.                         }
  43.  
  44.  
  45.  
  46.                     }
  47.                     break;
  48.                 case 2:
  49.                     if (accountcreated == true){
  50.                         System.out.println("What is your account name?");
  51.                         String namecheck = sc.nextLine();
  52.                         if(namecheck.equals(accountname)){
  53.                             System.out.println("What is your password?");
  54.                             String passcheck = sc.nextLine();
  55.                             if(passcheck.equals(password)) {
  56.                                 System.out.println("Would you like to withdraw or deposit? 1 for withdraw, 2 for deposit");
  57.                                 int depositorwithdraw = sc.nextInt();
  58.                                 sc.nextLine();
  59.                                 if (depositorwithdraw == 1) {
  60.                                     System.out.println("How much you would like to withdraw?");
  61.                                     double amountwithdrawed = sc.nextDouble();
  62.                                     sc.nextLine();
  63.                                     if (amountwithdrawed > balance) {
  64.                                         System.out.println("You do not have enough money to withdraw that much.");
  65.  
  66.                                     } else if (amountwithdrawed <= balance) {
  67.                                         balance = balance - amountwithdrawed;
  68.                                         wallet = amountwithdrawed + wallet;
  69.                                         System.out.println(amountwithdrawed + "$ has been withdrawed. You have " + balance + "$ in your bank account, and " + wallet + " in your wallet. Thank you for using Chingo Bank.");
  70.                                         System.out.println("Press 1 to back to menu");
  71.  
  72.                                     }
  73.                                 }
  74.                                 if (depositorwithdraw == 2) {
  75.                                     System.out.println("How much would you like to deposit?");
  76.                                     double amountdeposited = sc.nextDouble();
  77.                                     sc.nextLine();
  78.                                     if (amountdeposited > wallet) {
  79.                                         System.out.println("You do not have that much money.");
  80.                                     } else if (amountdeposited <= wallet) {
  81.                                         balance = balance + amountdeposited;
  82.                                         wallet = wallet - amountdeposited;
  83.                                         System.out.println(amountdeposited + "$ has been deposited. You have " + balance + "$ in your bank account, and " + wallet + "$ in your wallet.");
  84.                                     }
  85.  
  86.                                 }
  87.                             } else{
  88.                                 System.out.println("Password is wrong. Try again later.");
  89.                             }
  90.  
  91.  
  92.                         } else {
  93.                             System.out.println("Account has not been found. Try later.");
  94.                         }
  95.  
  96.  
  97.                     } else {
  98.                         System.out.println("Account has not been created. Please make an account before trying to withdraw/deposit.");
  99.                     }
  100.  
  101.                     break;
  102.                 case 3:
  103.                     if(accountcreated==false){
  104.                         System.out.println("You have not created an account. Please create an account before trying to edit your account details.");
  105.                     } else if(accountcreated==true){
  106.                         System.out.println("Choose one of the options below.");
  107.                         System.out.println("1. Change account name");
  108.                         System.out.println("2. Change account password");
  109.                         System.out.println("3. Back to menu");
  110.                         int accountchoice = sc.nextInt();
  111.                         sc.nextLine();
  112.                         switch(accountchoice){
  113.                             case 1:
  114.                                 System.out.println("Enter your current account name to change your account name.");
  115.                                 String changename = sc.nextLine();
  116.                                 if(changename.equals(accountname)){
  117.                                     System.out.println("Now enter your current password.");
  118.                                     String detailspass = sc.nextLine();
  119.                                     if(detailspass.equals(password)){
  120.                                         System.out.println("Account has been found and verified. Please enter your new account name");
  121.                                         accountname= sc.nextLine();
  122.                                         System.out.println("Account name has been changed to "+accountname+". Thank you for using Chingo Bank.");
  123.                                         break;
  124.                                     } else if (!(detailspass.equals(password))){
  125.                                         System.out.println("Wrong password. Try again later.");
  126.                                     }
  127.  
  128.                                 } else if(!(changename.equals(accountname))){
  129.                                     System.out.println("Wrong account name. Account has not been found. Try again later.");
  130.                                 }
  131.                                 break;
  132.                             case 2:
  133.                                 System.out.println("To change your password, you must enter your account name below first.");
  134.                                 String passname = sc.nextLine();
  135.                                 if(passname.equals(accountname)){
  136.                                     System.out.println("Now enter your current password.");
  137.                                     String detailspass = sc.nextLine();
  138.                                     if(detailspass.equals(password)){
  139.                                         System.out.println("Account has been found and verified. Please enter your password");
  140.                                         password= sc.nextLine();
  141.                                         System.out.println("Account password has been changed to "+password+". Thank you for using Chingo Bank.");
  142.                                         break;
  143.                                     } else if (!(detailspass.equals(password))){
  144.                                         System.out.println("Wrong password. Try again later.");
  145.                                     }
  146.  
  147.                                 } else if(!(passname.equals(accountname))){
  148.                                     System.out.println("Wrong account name. Account has not been found. Try again later.");
  149.                                 }
  150.                                 break;
  151.                             case 3:
  152.                                 System.out.println("Going back to menu...");
  153.                         break;
  154.                         }
  155.  
  156.                     }
  157.                     break;
  158.                 case 4:
  159.                     if (accountcreated == true) {
  160.                         System.out.println("What is your account name?");
  161.                         String ncheck = sc.nextLine();
  162.                         if (ncheck.equals(accountname)) {
  163.                             System.out.println("What is your password?");
  164.                             String pcheck = sc.nextLine();
  165.                             if (pcheck.equals(password)) {
  166.                                 System.out.println("You currently have $"+balance+" in your bank account.");
  167.                                 System.out.println("Press 1 to go back to menu.");
  168.                                 int fourmenu = sc.nextInt();
  169.                                 sc.nextLine();
  170.                                 if(fourmenu==1){
  171.                                     break;
  172.                                 }
  173.  
  174.                             }
  175.                         }
  176.                     } else if(accountcreated==false){
  177.                         System.out.println("Please create an account before trying to check your balance.");
  178.                         break;
  179.                     }
  180.  
  181.                 case 5:
  182.                     System.out.println("Exited.");
  183.                     break;
  184.             }
  185.            if (choice==5){
  186.                break;
  187.            }
  188.  
  189.         }
  190.  
  191.  
  192.  
  193.  
  194.     }
  195. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement