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: ");
String accountPhoneNumber = sc.next();
if (isPhoneNumberCorrect(accountPhoneNumber)) {
Account accountToTransfer = isAccountExist(accountPhoneNumber);
System.out.println("Enter the amount of money you would like to transfer:");
double moneyToTransfer = sc.nextDouble();
selectedAccount.moneyTransfer(selectedAccount, accountToTransfer, moneyToTransfer);
break;
}
case 5:
exitRequested = true;
break;
default:
System.out.println("Wrong input");
break;
}
}
}
}

public static boolean isPhoneNumberCorrect(String phoneNumber){
if(phoneNumber.length() != 10){
System.out.println("Phone number must be 10 digits.");
return false;

} else {
return true;
}
}
PrintService.java
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
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:09] ENTREPRENEUR: private final String firstName;
private final String lastName;
private double balance;
private static int uid = 0;
private final String phoneNumber;
private final int id;


public Account(String firstName, String lastName, String phoneNumber){
this.firstName = firstName;
this.lastName = lastName;
this.phoneNumber = phoneNumber;
this.balance = 0.0;
uid++;
this.id = uid;
}

public String getFirstName(){
return this.firstName + "";
}
public String getLastName(){
return this.lastName + "";
}
public double getBalance(){
return this.balance;
}
public void setBalance(double newBalance) {
this.balance = newBalance;
}
public int getID(){
return this.id;
}
public String getPhoneNumber(){
return this.phoneNumber + "";
}

public void depositMoney(double depositAmount){
this.balance += depositAmount;
System.out.println("You have deposit " +depositAmount +" to your account." + "\n" +
"Balance is now: " +this.balance);
}

public void withdrawal(double withdrawalAmount){
if(this.balance < withdrawalAmount) {
System.out.println("You don't have enough funds.");
} else {
this.balance -= withdrawalAmount;
System.out.println("You have withdrawal " +withdrawalAmount + " from your account." + "\n" +
"Balance is now: " +this.balance);
}
}

public void moneyTransfer(Account thisAccount, Account toAccount, double amountToTransfer){
if(thisAccount.getBalance() > 0) {
toAccount.setBalance(toAccount.balance += amountToTransfer);
thisAccount.setBalance(this.balance -= amountToTransfer);
} else {
System.out.println("You don't have enough funds");
}
}
@Override
public String toString(){
return "Name: " + getFirstName() + "\n" +
"Last name: " +getLastName() +"\n" +
"Balance: " + getBalance() + "\n" +
"ID: " + getID();
}
Bank.java
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;
}
private final String firstName;
private final String lastName;
private double balance;
private static int uid = 0;
private final String phoneNumber;
private final int id;


public Account(String firstName, String lastName, String phoneNumber){
this.firstName = firstName;
this.lastName = lastName;
this.phoneNumber = phoneNumber;
this.balance = 0.0;
uid++;
this.id = uid;
}

public String getFirstName(){
return this.firstName + "";
}
public String getLastName(){
return this.lastName + "";
}
public double getBalance(){
return this.balance;
}
public void setBalance(double newBalance) {
this.balance = newBalance;
}
public int getID(){
return this.id;
}
public String getPhoneNumber(){
return this.phoneNumber + "";
}

public void depositMoney(double depositAmount){
this.balance += depositAmount;
System.out.println("You have deposit " +depositAmount +" to your account." + "\n" +
"Balance is now: " +this.balance);
}

public void withdrawal(double withdrawalAmount){
if(this.balance < withdrawalAmount) {
System.out.println("You don't have enough funds.");
} else {
this.balance -= withdrawalAmount;
System.out.println("You have withdrawal " +withdrawalAmount + " from your account." + "\n" +
"Balance is now: " +this.balance);
}
}

public void moneyTransfer(Account thisAccount, Account toAccount, double amountToTransfer){
if(thisAccount.getBalance() > 0) {
toAccount.setBalance(toAccount.balance += amountToTransfer);
thisAccount.setBalance(this.balance -= amountToTransfer);
} else {
System.out.println("You don't have enough funds");
}
}

@Override
public String toString(){
return "Name: " + getFirstName() + "\n" +
"Last name: " +getLastName() +"\n" +
"Balance: " + getBalance() + "\n" +
"ID: " + getID();
}
Bank.java
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;
}
U guy's are in class or lab