Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Entity;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Scanner;
- public class BankAccount_1_2 {
- private int accountNumber;
- private String cusName;
- private double accountBalance;
- private char[] password;
- private double interestRate;
- private double automaticDepositAmt;
- private double automaticWithdrawAmt;
- public static List<BankAccount_1_2> bankAccountList = new ArrayList<>();
- public BankAccount_1_2(int accountNumber, String cusName, double accountBalance, char[] password, double interestRate, double automaticDepositAmt, double automaticWithdrawAmt) {
- this.accountNumber = accountNumber;
- this.cusName = cusName;
- this.accountBalance = accountBalance;
- this.password = password;
- this.interestRate = interestRate;
- this.automaticDepositAmt = automaticDepositAmt;
- this.automaticWithdrawAmt = automaticWithdrawAmt;
- }
- public double getAccountBalance() {
- return accountBalance;
- }
- public static void computeInterest(BankAccount_1_2 customer){
- int numberOfYears = 0;
- double interestRate = 0;
- Scanner sc = new Scanner(System.in);
- double currentAccountBalance = customer.accountBalance;
- System.out.println("Enter the number of Years Account is going to earn interest");
- numberOfYears = sc.nextInt();
- System.out.println("Enter the Interest Rate");
- interestRate = sc.nextDouble();
- for (int i = 1; i <= numberOfYears; i++){
- currentAccountBalance += ( currentAccountBalance * interestRate ) / 100;
- System.out.println("Year " + i + " Balance : $" + currentAccountBalance);
- }
- }
- public static BankAccount_1_2 enterAccountData(){
- Scanner usrDetails = new Scanner(System.in);
- int accNumber = 0;
- double accBalance = 0;
- double interestRate = 0;
- System.out.println("Enter the Account Number");
- boolean dupplicateAccNumber = false;
- do {
- accNumber = usrDetails.nextInt();
- if (accNumber == 0) {
- break;
- } else {
- if (accNumber < 1000 || accNumber > 9999) {
- System.out.println("Account number is not valid. Please enter a valid account number");
- }
- }
- for (BankAccount_1_2 account:bankAccountList)
- {
- if (account.accountNumber == accNumber){
- System.out.println("Account Number you entered already exists, Please enter a different account number");
- dupplicateAccNumber = true;
- } else {
- dupplicateAccNumber = false;
- }
- }
- } while (accNumber < 1000 || accNumber > 9999 || dupplicateAccNumber );
- System.out.println("Enter the Customer Name");
- String custName = usrDetails.next();
- System.out.println("Enter the account Balance");
- do {
- accBalance = usrDetails.nextDouble();
- if (accBalance < 0){
- System.out.println("Account balance cannot be Negetive. Please enter a positive Value");
- }
- } while (accBalance < 0);
- System.out.println("Enter the Account Password");
- char psswd[] = usrDetails.next().toCharArray();
- do {
- System.out.println("Enter the Interest Rate");
- interestRate = usrDetails.nextDouble();
- if (interestRate < 0.01 && interestRate > 15.0) {
- System.out.println("Please enter a valid Interest Rate.");
- }
- } while (interestRate < 0.01 && interestRate > 15.0);
- System.out.println("Enter the automatic Deposit Amount");
- double automaticDepositAmt = usrDetails.nextDouble();
- System.out.println("Enter the automatic withdraw Amount");
- double automaticWithdrawAmt = usrDetails.nextDouble();
- BankAccount_1_2 customer = new BankAccount_1_2(accNumber, custName, accBalance, psswd,interestRate,automaticDepositAmt,automaticWithdrawAmt);
- return customer;
- }
- public static void displayAccount(List<BankAccount_1_2> tempList){
- Scanner sc = new Scanner(System.in);
- BankAccount_1_2 searchedCustomer = null;
- System.out.println("Enter the Account number of the Account you want to Search");
- int accNumber = sc.nextInt();
- for (int i = 0; i < tempList.size(); i++) {
- if (tempList.get(i).accountNumber == accNumber){
- searchedCustomer = tempList.get(i);
- System.out.println("Account Number : " + searchedCustomer.accountNumber);
- System.out.println("Customer Name : " + searchedCustomer.cusName);
- System.out.println("Account Balance : $" + searchedCustomer.accountBalance);
- } else {
- System.out.println("Searched Account Number is not a valid Number");
- }
- }
- }
- public static void showList(List<BankAccount_1_2> baList){
- for (BankAccount_1_2 account:baList){
- System.out.println("Account Number : " + account.accountNumber);
- System.out.println("Account Balance : $" + account.accountBalance);
- System.out.println("");
- }
- }
- public static void creditMoney(BankAccount_1_2 object, double amount){
- object.accountBalance -= amount;
- }
- public static void depositMoney(BankAccount_1_2 object, double amount){
- object.accountBalance += amount;
- }
- public static void calculateEndingBalance(BankAccount_1_2 obj){
- double interest = ( obj.interestRate * 1/12 ) * obj.accountBalance;
- System.out.println("| Year | | Month | |Starting Balance| |Ending Balance|");
- for (int j = 1; j <= 2; j++) {
- for (int i = 1; i <= 12; i++) {
- double startingBalance = obj.accountBalance;
- double endingBalance = obj.accountBalance + interest + obj.automaticDepositAmt - obj.automaticWithdrawAmt;
- obj.accountBalance = obj.accountBalance + interest + obj.automaticDepositAmt - obj.automaticWithdrawAmt;
- System.out.println(" " + j + " " + i + " $" + startingBalance + " $" + endingBalance);
- }
- }
- }
- public static void main(String args[]){
- Scanner sc1 = new Scanner(System.in);
- String username = "";
- String password = "";
- double transferAmount = 0;
- Scanner usrDetails = new Scanner(System.in);
- int userChoice = 1;
- BankAccount_1_2 customer = null;
- System.out.println("Enter your Username");
- username = sc1.next();
- if (username.equals("admin")) {
- System.out.println("Enter your Password");
- password = sc1.next();
- if (password.equals("admin")){
- do {
- enterAccountData();
- bankAccountList.add(customer);
- calculateEndingBalance(customer);
- System.out.println("");
- computeInterest(customer);
- System.out.println("Do you want to add another account ? press number 1 to yes , 2 to No");
- userChoice = usrDetails.nextInt();
- } while (customer.accountNumber == 0);
- showList(bankAccountList);
- System.out.println("Do you want to transfer money from first Account to Seccond Account.(Yes press number 1, No Press number 2)");
- int choice = sc1.nextInt();
- if(choice == 1){
- System.out.println("Enter the Amount to be Transferred");
- do {
- transferAmount = sc1.nextDouble();
- if ((bankAccountList.get(0).getAccountBalance() - transferAmount) < 0) {
- System.out.println("You dont have enough balance in Account 1 to do the Transaction, Please enter a different Amount");
- } else
- if ((bankAccountList.get(0).getAccountBalance() - transferAmount) < 10) {
- System.out.println("Warning : After this Transaction Account 1 account balance will be less than $10");
- }
- if ((bankAccountList.get(0).getAccountBalance() - transferAmount) > 100000) {
- System.out.println("Warning : Account 2 Balance will be higher than highest amount that is federally insured.");
- }
- } while ((bankAccountList.get(0).getAccountBalance() - transferAmount) < 0);
- creditMoney(bankAccountList.get(0),transferAmount);
- depositMoney(bankAccountList.get(1),transferAmount);
- }
- System.out.println("After Transfer");
- showList(bankAccountList);
- System.out.println("Press 1 to Search For Search for Bank Accounts , 2 to Quit");
- int finalChoice = sc1.nextInt();
- if (finalChoice == 1){
- displayAccount(bankAccountList);
- } else if (finalChoice == 2) {
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement