Skip to content

Commit

Permalink
Merge pull request #15 from fredrick-kamau1/stage-3
Browse files Browse the repository at this point in the history
Splitting code into classes for usability
  • Loading branch information
fkamau1 authored Feb 20, 2023
2 parents d30e222 + 6318afb commit 2b996e5
Showing 1 changed file with 90 additions and 0 deletions.
90 changes: 90 additions & 0 deletions app/src/main/java/bankingapp/CreateAccount.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package bankingapp;

import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;
import java.util.Random;
import java.util.Scanner;

/**
* @author Fredrick Class CreateAccount that creates a new bank account for the user. The user is required to provide
* their first and last name, the system will in turn generate a random account number and PIN-number.
*/
public class CreateAccount {

String firstName;
String lastName;
String accountNumber;
int pin;
HashMap<String, Integer> account;
Statement statement;
Scanner input;

CreateAccount(){
this.firstName = getFirstName();
}


/**
*
* @param statement
* @param account
* @throws SQLException
*/
public static void createAccount(Statement statement, HashMap<String, Integer> account) throws SQLException {
Random rand = new Random();
Random rand2 = new Random();
long upper = 999999999L;
long lower = 100000000L;
String accountNum = "400000" + (rand.nextLong(upper - lower + 1) + lower);

accountNum = checkSumNum(accountNum);

int pinNum = rand2.nextInt(9999 - 1000 + 1) + 1000;
System.out.println("\nYour card has been created\nYour card number:\n" + accountNum +
"\nYour card PIN:\n" + pinNum);
account.put(accountNum, pinNum);



//insertDB(statement, accountNum, String.valueOf(pinNum));

}

/**
* Getter method to get the first name
* @return firstName
*/
public String getFirstName() {
System.out.println("Enter First Name:");
return firstName = input.nextLine();
}


/**
* Getter method to get the last name
* @return lastName
*/
public String getLastName() {
System.out.println("Enter Last Name:");
return lastName = input.nextLine();
}

/**
* Getter method to get the Account Number
* @return accountNumber
*/
public String getAccountNumber() {
Random rand = new Random();

return accountNumber;
}

/**
* Getter method to get the PIN-number
* @return
*/
public int getPin() {
return pin;
}
}

0 comments on commit 2b996e5

Please sign in to comment.