Advertisement
Guest User

Untitled

a guest
Mar 11th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.61 KB | None | 0 0
  1. package Entity;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import java.util.Scanner;
  6.  
  7. public class BankAccount_1_2 {
  8.     private int accountNumber;
  9.     private String cusName;
  10.     private double accountBalance;
  11.     private char[] password;
  12.     private double interestRate;
  13.     private double automaticDepositAmt;
  14.     private double automaticWithdrawAmt;
  15.  
  16.     public static List<BankAccount_1_2> bankAccountList = new ArrayList<>();
  17.  
  18.     public BankAccount_1_2(int accountNumber, String cusName, double accountBalance, char[] password, double interestRate, double automaticDepositAmt, double automaticWithdrawAmt) {
  19.         this.accountNumber = accountNumber;
  20.         this.cusName = cusName;
  21.         this.accountBalance = accountBalance;
  22.         this.password = password;
  23.         this.interestRate = interestRate;
  24.         this.automaticDepositAmt = automaticDepositAmt;
  25.         this.automaticWithdrawAmt = automaticWithdrawAmt;
  26.     }
  27.  
  28.     public double getAccountBalance() {
  29.         return accountBalance;
  30.     }
  31.  
  32.     public static void computeInterest(BankAccount_1_2 customer){
  33.         int numberOfYears = 0;
  34.         double interestRate = 0;
  35.         Scanner sc = new Scanner(System.in);
  36.         double currentAccountBalance = customer.accountBalance;
  37.  
  38.         System.out.println("Enter the number of Years Account is going to earn interest");
  39.         numberOfYears = sc.nextInt();
  40.  
  41.         System.out.println("Enter the Interest Rate");
  42.         interestRate = sc.nextDouble();
  43.  
  44.  
  45.  
  46.         for (int i = 1; i <= numberOfYears; i++){
  47.             currentAccountBalance += ( currentAccountBalance * interestRate ) / 100;
  48.             System.out.println("Year " + i + " Balance : $" + currentAccountBalance);
  49.         }
  50.  
  51.     }
  52.  
  53.     public static BankAccount_1_2 enterAccountData(){
  54.  
  55.         Scanner usrDetails = new Scanner(System.in);
  56.         int accNumber = 0;
  57.         double accBalance = 0;
  58.         double interestRate = 0;
  59.  
  60.  
  61.             System.out.println("Enter the Account Number");
  62.             boolean dupplicateAccNumber = false;
  63.  
  64.             do {
  65.                 accNumber = usrDetails.nextInt();
  66.  
  67.                 if (accNumber == 0) {
  68.                     break;
  69.                 } else {
  70.                     if (accNumber < 1000 || accNumber > 9999) {
  71.                         System.out.println("Account number is not valid. Please enter a valid account number");
  72.                     }
  73.                 }
  74.  
  75.  
  76.                 for (BankAccount_1_2 account:bankAccountList)
  77.                 {
  78.                     if (account.accountNumber == accNumber){
  79.                         System.out.println("Account Number you entered already exists, Please enter a different account number");
  80.                         dupplicateAccNumber = true;
  81.                     } else {
  82.                         dupplicateAccNumber = false;
  83.                     }
  84.  
  85.                 }
  86.  
  87.             } while (accNumber < 1000 || accNumber > 9999 || dupplicateAccNumber );
  88.  
  89.             System.out.println("Enter the Customer Name");
  90.             String custName = usrDetails.next();
  91.  
  92.             System.out.println("Enter the account Balance");
  93.             do {
  94.                 accBalance = usrDetails.nextDouble();
  95.  
  96.                 if (accBalance < 0){
  97.                     System.out.println("Account balance cannot be Negetive. Please enter a positive Value");
  98.                 }
  99.  
  100.             } while (accBalance < 0);
  101.  
  102.             System.out.println("Enter the Account Password");
  103.             char psswd[] = usrDetails.next().toCharArray();
  104.  
  105.             do {
  106.                 System.out.println("Enter the Interest Rate");
  107.                 interestRate = usrDetails.nextDouble();
  108.  
  109.                 if (interestRate < 0.01 && interestRate > 15.0) {
  110.                     System.out.println("Please enter a valid Interest Rate.");
  111.                 }
  112.             } while (interestRate < 0.01 && interestRate > 15.0);
  113.  
  114.             System.out.println("Enter the automatic Deposit Amount");
  115.             double automaticDepositAmt = usrDetails.nextDouble();
  116.  
  117.             System.out.println("Enter the automatic withdraw Amount");
  118.             double automaticWithdrawAmt = usrDetails.nextDouble();
  119.  
  120.             BankAccount_1_2 customer = new BankAccount_1_2(accNumber, custName, accBalance, psswd,interestRate,automaticDepositAmt,automaticWithdrawAmt);
  121.  
  122.         return customer;
  123.  
  124.     }
  125.     public static void displayAccount(List<BankAccount_1_2> tempList){
  126.         Scanner sc = new Scanner(System.in);
  127.         BankAccount_1_2 searchedCustomer = null;
  128.         System.out.println("Enter the Account number of the Account you want to Search");
  129.         int accNumber = sc.nextInt();
  130.  
  131.         for (int i = 0; i < tempList.size(); i++) {
  132.  
  133.             if (tempList.get(i).accountNumber == accNumber){
  134.                 searchedCustomer = tempList.get(i);
  135.  
  136.                 System.out.println("Account Number : " + searchedCustomer.accountNumber);
  137.                 System.out.println("Customer Name : " + searchedCustomer.cusName);
  138.                 System.out.println("Account Balance : $" + searchedCustomer.accountBalance);
  139.             } else {
  140.                 System.out.println("Searched Account Number is not a valid Number");
  141.             }
  142.  
  143.         }
  144.     }
  145.  
  146.     public static void showList(List<BankAccount_1_2> baList){
  147.  
  148.         for (BankAccount_1_2 account:baList){
  149.             System.out.println("Account Number : " + account.accountNumber);
  150.             System.out.println("Account Balance : $" + account.accountBalance);
  151.             System.out.println("");
  152.         }
  153.     }
  154.  
  155.     public static void creditMoney(BankAccount_1_2 object, double amount){
  156.  
  157.         object.accountBalance -= amount;
  158.     }
  159.  
  160.     public static void depositMoney(BankAccount_1_2 object, double amount){
  161.  
  162.         object.accountBalance += amount;
  163.     }
  164.  
  165.     public static void calculateEndingBalance(BankAccount_1_2 obj){
  166.  
  167.         double interest = ( obj.interestRate * 1/12 ) * obj.accountBalance;
  168.  
  169.         System.out.println("| Year | | Month | |Starting Balance| |Ending Balance|");
  170.  
  171.         for (int j = 1; j <= 2; j++) {
  172.             for (int i = 1; i <= 12; i++) {
  173.  
  174.                 double startingBalance = obj.accountBalance;
  175.                 double endingBalance = obj.accountBalance + interest + obj.automaticDepositAmt - obj.automaticWithdrawAmt;
  176.                 obj.accountBalance = obj.accountBalance + interest + obj.automaticDepositAmt - obj.automaticWithdrawAmt;
  177.  
  178.                 System.out.println("  " + j + "        " + i + "           $" + startingBalance + "             $" + endingBalance);
  179.             }
  180.         }
  181.  
  182.     }
  183.  
  184.  
  185.  
  186.     public static void main(String args[]){
  187.  
  188.         Scanner sc1 = new Scanner(System.in);
  189.         String username = "";
  190.         String password = "";
  191.         double transferAmount = 0;
  192.         Scanner usrDetails = new Scanner(System.in);
  193.         int userChoice = 1;
  194.         BankAccount_1_2 customer = null;
  195.  
  196.         System.out.println("Enter your Username");
  197.         username = sc1.next();
  198.  
  199.         if (username.equals("admin")) {
  200.  
  201.             System.out.println("Enter your Password");
  202.             password = sc1.next();
  203.  
  204.             if (password.equals("admin")){
  205.  
  206.                 do {
  207.  
  208.                     enterAccountData();
  209.  
  210.                     bankAccountList.add(customer);
  211.  
  212.                     calculateEndingBalance(customer);
  213.  
  214.                     System.out.println("");
  215.  
  216.                     computeInterest(customer);
  217.  
  218.                     System.out.println("Do you want to add another account ? press number 1 to yes , 2 to No");
  219.                     userChoice = usrDetails.nextInt();
  220.  
  221.                 } while (customer.accountNumber == 0);
  222.  
  223.  
  224.                 showList(bankAccountList);
  225.  
  226.  
  227.                 System.out.println("Do you want to transfer money from first Account to Seccond Account.(Yes press number 1, No Press number 2)");
  228.  
  229.                 int choice = sc1.nextInt();
  230.  
  231.                 if(choice == 1){
  232.                     System.out.println("Enter the Amount to be Transferred");
  233.  
  234.                     do {
  235.                         transferAmount = sc1.nextDouble();
  236.  
  237.                         if ((bankAccountList.get(0).getAccountBalance() - transferAmount) < 0) {
  238.                             System.out.println("You dont have enough balance in Account 1 to do the Transaction, Please enter a different Amount");
  239.                         } else
  240.                         if ((bankAccountList.get(0).getAccountBalance() - transferAmount) < 10) {
  241.                             System.out.println("Warning : After this Transaction Account 1 account balance will be less than $10");
  242.                         }
  243.                         if ((bankAccountList.get(0).getAccountBalance() - transferAmount) > 100000) {
  244.                             System.out.println("Warning : Account 2 Balance will be higher than highest amount that is federally insured.");
  245.                         }
  246.                     } while ((bankAccountList.get(0).getAccountBalance() - transferAmount) < 0);
  247.  
  248.  
  249.  
  250.                     creditMoney(bankAccountList.get(0),transferAmount);
  251.                     depositMoney(bankAccountList.get(1),transferAmount);
  252.                 }
  253.  
  254.                 System.out.println("After Transfer");
  255.                 showList(bankAccountList);
  256.  
  257.                 System.out.println("Press 1 to Search For Search for Bank Accounts , 2 to Quit");
  258.  
  259.                 int finalChoice = sc1.nextInt();
  260.  
  261.                 if (finalChoice == 1){
  262.                     displayAccount(bankAccountList);
  263.                 } else if (finalChoice == 2) {
  264.  
  265.                 }
  266.  
  267.             }
  268.  
  269.         }
  270.  
  271.     }
  272.  
  273. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement