Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package tumacay_bank;
- import java.io.BufferedReader;
- import java.io.FileReader;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.Iterator;
- import java.util.Objects;
- import java.util.Scanner;
- /**
- *
- * @author S202-11
- */
- public class Tumacay_Bank {
- /**
- * @param args the command line arguments
- */
- //static Scanner input;
- static int SampleAccountNo = 12345;
- static int SampleAccountPIN = 1234;
- static int SampleAccountCash = 20000;
- static double Cash;
- static Scanner input;
- static ArrayList<String> ValidAccountNos;
- public static void main(String[] args) throws IOException {
- // TODO code application logic here
- /* LOAD THE DATABASE */
- ValidAccountNos = new ArrayList<String>();
- try (BufferedReader br = new BufferedReader(new FileReader("database.txt"))) {
- String line;
- while ((line = br.readLine()) != null) {
- //System.out.println(line);
- if( contains( line, "[DATA]")) {
- //System.out.println( "Found [DATA] within " + line + "." );
- String[] parts = line.split(",");
- ValidAccountNos.add(parts[2]);
- }
- // process the line.
- }
- }
- // int twoDimenArray[][] = new int[3][5];
- // int i, j, k = 0;
- //
- // for(i = 0; i < 3; i++) {
- // for(j = 0; j < 5; j++) {
- // twoDimenArray[i][j] = k;
- // k++;
- // }
- // }
- // for(Iterator<String> i = ValidAccountNos.iterator(); i.hasNext(); ) {
- // String item = i.next();
- // System.out.println(item);
- // }
- //String[] AccountName;
- // for(int NoOfPeople = 1; NoOfPeople <= 10; NoOfPeople++) {
- // String[] AccountName = null;
- //
- // AccountName[NoOfPeople] = "Juan Tamad";
- // System.out.println(AccountName[NoOfPeople]);
- // //int[] AccountNo = {12345};
- // }
- //Home();
- //ERROR
- // int AccountNoErrorCount = 0, AccountNoInput;
- //
- // while(AccountNoErrorCount <= 2)
- // {
- // AccountNoErrorCount++;
- // System.out.println("Account No: ");
- //
- // AccountNoInput = input.nextInt();
- // System.out.println("No. of tries: " + AccountNoErrorCount);
- // }
- }
- public static void Home() {
- System.out.println("\n Welcome to LPU Bank System.\n");
- input = new Scanner(System.in);
- //int AccountNoInput = input.nextInt();
- System.out.println("[TRANSACTION]");
- System.out.println("1. Deposit");
- System.out.println("2. Withdraw");
- System.out.println("3. Balance Inquiry");
- System.out.println("4. Exit");
- System.out.println("\nOption: ");
- int Option = input.nextInt();
- switch(Option) {
- case 1:
- System.out.println("[DEPOSIT TRANSACTION]");
- System.out.println("Cash: ");
- Cash = input.nextDouble();
- Deposit(SampleAccountNo, Cash);
- break;
- case 2:
- System.out.println("[WITHDRAW TRANSACTION]");
- System.out.println("Cash: ");
- Cash = input.nextDouble();
- Withdraw(SampleAccountNo, Cash);
- break;
- case 3:
- BalanceInquiry(SampleAccountNo);
- break;
- case 4:
- Exit();
- break;
- default:
- System.out.println("\nINVALID OPTION!");
- Home();
- break;
- }
- }
- public static void Deposit(int AccountNo, double Cash) {
- //AccountNo += Cash;
- SampleAccountCash += Cash;
- System.out.println("[RECEIT RECEIPT]");
- System.out.println("Account Name: " + "Sample Account Name");
- System.out.println("Account No.: " + AccountNo);
- System.out.println("Balance: " + (SampleAccountCash - Cash));
- System.out.println("Deposit: " + Cash);
- System.out.println("New Balance: " + SampleAccountCash);
- Home();
- }
- public static void Withdraw(int AccountNo, double Cash) {
- //AccountNo -= Cash;
- SampleAccountCash -= Cash;
- System.out.println("[WITHDRAW RECEIPT]");
- System.out.println("Account No.: " + AccountNo);
- System.out.println("Balance: " + (SampleAccountCash + Cash));
- System.out.println("Withdraw: " + Cash);
- System.out.println("New Balance: " + SampleAccountCash);
- Home();
- }
- public static void BalanceInquiry(int AccountNo) {
- System.out.println("[BALANCE INQUIRY]");
- System.out.println("Account No.: " + AccountNo);
- System.out.println("Balance: " + SampleAccountCash);
- Home();
- }
- public static void Exit() {
- Boolean Repeat = true;
- while(Repeat)
- {
- System.out.println("Do you want to make another transaction? Y or N");
- String RepeatInput = input.next();
- switch(RepeatInput) {
- case "Y":
- Home();
- break;
- case "y":
- Home();
- break;
- case "N":
- System.exit(0);
- break;
- case "n":
- System.exit(0);
- break;
- default:
- System.out.println("\nINVALID OPTION!");
- Exit();
- break;
- }
- }
- //System.exit(0);
- }
- public static boolean contains( String haystack, String needle ) {
- haystack = haystack == null ? "" : haystack;
- needle = needle == null ? "" : needle;
- // Works, but is not the best.
- //return haystack.toLowerCase().indexOf( needle.toLowerCase() ) > -1
- return haystack.toLowerCase().contains( needle.toLowerCase() );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement