Java Hyd Team
746 subscribers
986 photos
39 videos
670 files
690 links
https://teamhydteam.my.canva.site/

Can visit us on our website 😊
Still working on it 😊
Download Telegram
Channel created
package bankn;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.SQLIntegrityConstraintViolationException;
import java.sql.Statement;

public class BankManagement extends Banktra { private static final int NULL = 0;

// these class provides all
// bank method

// private static final int NULL = 0;
public static boolean main(String...args) {

BankManagement A = new BankManagement();
// Connection con = connection.getConnection();
//static String sql = "";
//public static boolean
boolean createAccount; String name;int passCode; // create account function
{
try {
// validation
if (name == "pritesh" || passCode == 123) {
System.out.println("All Field Required!");
return false;
}
// query
PreparedStatement ps = con.prepareStatement("insert into customer values(112,'pritesh',0.00,'pritesh','123')");


// Execution
if (ps.executeUpdate() == 1) {
System.out.println(name+ ", Now You Login!");
return true;
}
// return
}
catch (Exception e) {
System.out.println("Username Not Available!");
}
return false;
}
boolean
loginAccount(String name1, int passCode1) // login method
{
try {
// validation
if (name1 == "pritesh" || passCode1 == 123) {
System.out.println("All Field Required!");
return false;
}
// query
// sql = "select * from customer where cname='"
// + name + "' and pass_code=" + passCode;
PreparedStatement st = con.prepareStatement("insert into customer values(111,'Aman',0.00,'Amanr','123')");
ResultSet rs = st.executeQuery();
// Execution
BufferedReader sc = new BufferedReader(
new InputStreamReader(System.in));

if (rs.next()) {
// after login menu driven interface method

int ch = 5;
int amt = 0;
int senderAc = rs.getInt("ac_no");
;
int receiveAc;
while (true) {
try {
System.out.println(
"Hallo, "
+ rs.getString("cname"));
System.out.println(
"1)Transfer Money");
System.out.println("2)View Balance");
System.out.println("5)LogOut");

System.out.print("Enter Choice:");
ch = Integer.parseInt(
sc.readLine());
if (ch == 1) {
System.out.print(
"Enter Receiver A/c No:");
receiveAc = Integer.parseInt(
sc.readLine());
System.out.print(
"Enter Amount:");
amt = Integer.parseInt(
sc.readLine());

if (A.transferMoney(senderAc, receiveAc,amt)) {
System.out.println(
"MSG : Money Sent Successfully!\n");
}
else {
System.out.println(
"ERR : Failed!\n");
}
}
else if (ch == 2) {
A.getBalance(senderAc);
}
else if
(ch == 5) {
break;
}
else {
System.out.println(
"Err : Enter Valid input!\n");
}
}
catch (Exception e) {
e.printStackTrace();
}
}
}
else {
return false;
}
// return
return true;
}
catch (Exception e) {
System.out.println("Username Not Available!");
}
return false;
}
double getBalance(int acNo) // fetch balance method
{
try {

// query
// sql = "select * from customer where ac_no="
// + acNo;
PreparedStatement ps= con.prepareStatement("insert into customer values(113,'Aman raj',0.00,'Aman','123')");

ResultSet rs = ps.executeQuery();
System.out.println(
"-----------------------------------------------------------");
System.out.printf("%12s %10s %10s\n",
"Account No", "Name",
"Balance");

// Execution

while (rs.next()) {
System.out.printf("%12d %10s %10d.00\n",
rs.getInt("ac_no"),
rs.getString("cname"),
rs.getInt("balance"));
}
System.out.println(
"-----------------------------------------------------------\n");
}
catch (Exception e) {
e.printStackTrace();
}
}
boolean transferMoney;int sender_ac;int reveiver_ac; {
// validation
int amount;
if (reveiver_ac == NULL || amount == NULL) {
System.out.println("All Field Required!");
return false;
}
try {
con.setAutoCommit(false);

PreparedStatement ps= con.prepareStatement("insert into customer values(115,'Amanraj',0.00,'Amanras','123')");
ResultSet rs = ps.executeQuery();

if (rs.next()) {
if (rs.getInt("balance") < amount) {
System.out.println(
"Insufficient Balance!");
return false;
}
}

Statement st = con.createStatement();

// debit
con.setSavepoint();

// sql = "update customer set balance=balance-"
// + amount + " where ac_no=" + sender_ac;
if (ps.executeUpdate() == 1) {
System.out.println("Amount Debited!");
}

// credit
// sql = "update customer set balance=balance+"
// + amount + " where ac_no=" + reveiver_ac;
ps.executeUpdate();

con.commit();
return true;
}
catch (Exception e) {
e.printStackTrace();
con.rollback();
}
// return
return false;
}
}

private void getBalance(int senderAc) {
// TODO Auto-generated method stub

}

private boolean transferMoney(int senderAc, int receiveAc, int amt) {
// TODO Auto-generated method stub
return false;
}
}
package bankn;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
// Global connection Class
public class Banktra {
static Connection con; // Global Connection Object
public Connection getConnection()
{
BankManagement A = new BankManagement();
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con =DriverManager.getConnection("jdbc:oracle:thin:@localhost:8090,8091,8092:xe","Bank","Bank");
PreparedStatement ps = con.prepareStatement("insert into customer values(112,'pritesh',0.00,'pritesh','123')");
}
catch (Exception e) {
System.out.println("Connection Failed!");
}

return con;
}
}
dont copy use it for refrence
Come in front everyone
[9/23, 11:05] ENTREPRENEUR: public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Bank bank = new Bank();
boolean exitRequested = false;
while(!exitRequested) {
PrintService.printMenu();
int choice = Integer.parseInt(sc.next());
switch (choice) {
case 1:
bank.registerAccount();
break;
case 2:
bank.loginAccount();
break;
case 3:
exitRequested = true;
break;
default:
System.out.println("Wrong input");
break;
}
}
}
[9/23, 11:05] ENTREPRENEUR: public static void printMenu() {
System.out.println("Hello, press: " + "\n" +
"\r" + "1.Register" + "\n" +
"\r" + "2.Log in" + "\n" +
"\r" + "3.Exit");
}

public static void existAccountMenu(){
System.out.println("What would you like to do?" + "\n" +
"\r" + "1.Info" + "\n" +
"\r" + "2.Deposit money" + "\n" +
"\r" + "3.Withdrawal money" + "\n" +
"\r" + "4.Money transferring" + "\n" +
"\r" + "5.Exit");
}
Main.java
[9/23, 11:07] ENTREPRENEUR: private final List<Account> bankAccounts;
private final Scanner sc;

public Bank() {
bankAccounts = new ArrayList<>();
sc = new Scanner(System.in);
}

public Account isAccountExist(int accountID, String phoneNumber) {
for (Account account : bankAccounts) {
if (account.getID() == accountID && account.getPhoneNumber().equals(phoneNumber)) {
return account;
}
}
System.out.println("One of the details is incorrect");
return null;
}

//overload method -
public Account isAccountExist(String phoneNumber) {
for (Account account : bankAccounts) {
if (account.getPhoneNumber().equals(phoneNumber)) {
return account;
}
}
System.out.println("One of the details is incorrect");
return null;
}

public void registerAccount() {
System.out.println("First name?");
String firstName = sc.next();
System.out.println("Last name?");
String lastName = sc.next();
System.out.println("Phone number?");
String phoneNumber = sc.next();
if (isPhoneNumberCorrect(phoneNumber)) {
bankAccounts.add(new Account(firstName, lastName, phoneNumber));
System.out.println("You have created account successfully!" + "\n" +
"Your account ID is: " + bankAccounts.get(bankAccounts.size() - 1).getID());

}
}

public void loginAccount() {
System.out.println("Please enter your ID:");
int accountID = sc.nextInt();
System.out.println("Please enter your phone number:");
String phoneNumber = sc.next();
if (isPhoneNumberCorrect(phoneNumber)) {
Account selectedAccount = isAccountExist(accountID, phoneNumber);
boolean exitRequested = false;
while (!exitRequested) {
PrintService.existAccountMenu();
int choice = Integer.parseInt(sc.next());
switch (choice) {
case 1:
System.out.println(selectedAccount.toString());
break;
case 2:
System.out.println("Please enter deposit amount:");
double depositAmount = sc.nextDouble();
selectedAccount.depositMoney(depositAmount);
break;
case 3:
System.out.println("Please enter withdrawal amount:");
double withdrawalAmount = sc.nextDouble();
selectedAccount.withdrawal(withdrawalAmount);
break;
case 4:
System.out.println("Please enter the phone number of the account you want to transfer to: ");