السلام عليكم
هذا برنامجي للبحث بنظام بنك للحصول على الرصيد واضافة اوخصم قيمه
الخطا فقط في ميثود البحث الثنائي وكيف يبحث في المصفوفه
بليييييز ابي الرد بسرررررررعه
import java.io.FileReader;
class besmellah {
protected double balance;
protected int accountNumber;
// default constructor
public besmellah()
{
System.out.println("BankAccount: default constructor called");
balance = 0.0;
accountNumber = 0;
}
// constructor, takes a balance and an account number
public besmellah(double aBalance, int aNumber)
{
System.out.println("BankAccount: constructor called with "
+ aBalance + " and " + aNumber);
balance = aBalance;
accountNumber = aNumber;
}
// put a specified amount of money into our account
public void deposit(double amt)
{
balance += amt;
// print something out so we can see which methods are
// being called
System.out.println("BankAccount: deposit " + amt +
" balance = " + balance);
}
// Take out a specified amount from our account.
// If there isn't enough in the account, don't take out any money
// and return false. Otherwise take the money and return true.
public boolean withdrawal(double amt)
{
if (balance < amt)
{
System.out.println("BankAccount: withdrawal " + amt +
" but we only have " + balance +
" in the account!");
return false;
}
balance -= amt;
// print something out so we can see which methods are
// being called
System.out.println("BankAccount: withdrawal " + amt +
" balance = " + balance);
return true;
}
// display information about this account
public void writeOutput()
{
System.out.println("Account #" + accountNumber + " $" +
balance);
}
public boolean equals(BankAccount otherAccount)
{
return (accountNumber == otherAccount.accountNumber);
}
}
class test{
public static void main(String args[]) {
try {
String[][]A=new String[11][1];
FileReader fr = new FileReader("bankFile.txt");
BufferedReader br = new BufferedReader (fr);
for(int i=0; i<11; i++ ){
for(j=0; j<1; j++)
A[j] = (String) br.readline();
}
fr.close();
} catch (Exception e) {
System.out.println("Exception: " + e);
}
public static final int NOT_FOUND = -1;
public static <T extends Comparable<? super T>>
int binarySearch( T [][] A, T x )
{
int low = 0;
int high =A.length() - 1;
int mid;
while( low <= high )
{
mid = ( low + high ) / 2;
if( A[ mid ][2].compareTo( x ) < 0 )
low = mid + 1;
else if( A[ mid ][2].compareTo( x ) > 0 )
high = mid - 1;
else
return mid;
}
return NOT_FOUND; // NOT_FOUND = -1
}
Integer [][] A = new Integer [][];
Arrays.sort(A);
// Search an element
int index = Arrays.binarySearch(A, 3);
}
}