I'm required to build a program in Java, while I have no idea about it.
I have an integer value stored in an object variable.. And I want to assign the value to another integer variable. but I can't find a way to convert an object to integer...
may you please help with this .. thanks in advance ..
Here is my Code :
public class Bank extends unicastRemoteObject implements BankInterface
{
String[] columnNames = {"Account","Balance"};
Object[][] data = {{"a",10,},{"b",20}};
public Bank() throws RemoteException { //constructor
}
public int getRowCount() { // number of accounts
return data.length;
}
public Object getValueAt(int row, int col) { // returns the value of the cell
return data[row][col];
}
public void deposit(int account, int amount) throws RemoteException {
// work Description:
// find the tuple by searching about the account number
// add the amount to balance..
// conversions are needed
Object accnum; // to store the account number in. *string*
Object balancevalue; // to store the balance in. *integer*
for ( int i=0 ; i<=getRowCount() ; i++)
balancevalue = getValueAt(i,2)); // assign the current balance value..
accnum = getValueAt(i,1); // assign the account number..
int a = 0; // we will assign the integer type of accnum to a.
int b = 0; // we will assign the integer type of balancevalue to b.
if( a == account ) { // we find the account number.
b= b + amount ; // add the amount to the balance.
// we need to change the integer "b" into Object to store it in Data[i][2].
}
}
String a = 0;is incompatible withif( a == account )since account is declared asint account. Either the method signature must be changed, or the declared type of the variable a must be changed, or the condition for the if statement must be changed to include conversions. Judging by the comments, I feel like the author of the assignment did not intend any of these things to be changed. I would say the person who wrote the assignment was being pretty sloppy, and didn't check his product for correctness.deposit(...)method takes two ints as input? Maybe the deposit method should take something else than two ints as input...