I've tried to run the BankServer.java class for several hours and this is the error it gives me:
G:\Distributed Objects\Exercise 3\BankServer.java:11: cannot find symbol
symbol : constructor BankImpl()
location: class BankImpl
BankImpl b = new BankImpl();
I have other classes orf the Bank interface, BankImpl and BankClient but they're all working fine. I've tried to add a no-argument constructor to BankImpl, or change the way I'm calling it to match one of the declared constructors but it stil wont work. here are all of the classes.ps help.
//Bank.java
//RMI interface.
import java.rmi.*;
public interface Bank extends Remote
{
public int getAcctNum() throws RemoteException;
public String getName() throws RemoteException;
public double getBalance() throws RemoteException;
public double withdraw(double amount) throws RemoteException;
public void deposit(double amount) throws RemoteException;
}
//BankImpl.java
//Implementation of RMI interface.
import java.rmi.*;
import java.rmi.server.*;
public class BankImpl implements Bank
{
private int accountNumber;
private String lastName;
private String firstName;
private double balance;
public BankImpl (int acctNo, String lname, String fname, double bal)
{
accountNumber = acctNo;
lastName = lname;
firstName = fname;
balance = bal;
}
public int getAcctNum() throws RemoteException
{
return accountNumber;
}
public String getName() throws RemoteException
{
return (firstName + " " + lastName);
}
public double getBalance() throws RemoteException
{
return balance;
}
public double withdraw(double amount) throws RemoteException
{
if (amount <= balance) return amount;
else return 0;
}
public void deposit(double amount) throws RemoteException
{
if (amount > 0) balance += amount;
}
}
//BankClient.java
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
public class BankClient
{
private static final int[] acctNo = {111111, 222222, 333333, 444444};
public static void main(String args[])
{
try{
//get remote objectreference (stub)
Registry registry = LocateRegistry.getRegistry("Localhost");
Bank b = (Bank)registry.lookup("BankService");
for (int i=0; i<acctNo.length; i++)
{
System.out.println("\nAccount number: " + b.getAcctNum());
System.out.println("Name: " + b.getName());
System.out.println("Balance: " + b.getBalance());
}
} catch (java.rmi.RemoteException re){
System.out.println("RemoteException");
System.out.println(re);
}
catch (java.rmi.NotBoundException nbe){
System.out.println("NotBoundException");
System.out.println(nbe);
}
catch (java.lang.ArithmeticException ae){
System.out.println("java.lang.ArithmeticException");
System.out.println(ae);
}
}
}
//BankServer.java
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
public class BankServer
{
public static void main(String[] args) throws Exception
{
try{
BankImpl b = new BankImpl();
//'0' denotes location where exported object 'c' is to be stored
Bank stub = (Bank)UnicastRemoteObject.exportObject(b,0);
Registry registry = LocateRegistry.getRegistry();
registry.rebind("BankService", stub);
System.out.println("Bank server running");
BankImpl[] account =
{new BankImpl(111111, "Smith", "James", 112.58),
new BankImpl(222222, "Jones", "Sally", 507.85),
new BankImpl(333333, "White", "Mary Jane", 2345.00),
new BankImpl(444444, "Brooks", "Mark", 10028.00)};
for (int i=0; i<account.length; i++)
{
int accountNumber= account[i].getAcctNum();
}
}catch(Exception e){
System.out.println("Trouble: " + e);
}
}
}