The code contains 4 methods
Dir is the constructor
addDetails is to get company Details ,
contact number and ratings for that particular company
and store it in arrays compName,compNumber and Rate respectively
which are String array,Int array and String array respectively.
Method getDetails takes a name as input and prints details of that particular company as output
Similarly getContact takes company name and gives contact number
public class Dir extends UnicastRemoteObject implements DirInterface {
Scanner sc=new Scanner(System.in);
public String compName[]=new String[50];
public int compNumber[]=new int[50];
public String Rate[]=new String[50];
public static int k=0;
public Dir() throws RemoteException {
super();
}
public void addDetails() {
System.out.println("Input company Details to add");
compName[k]=sc.nextLine();
System.out.println("input contact number of company");
compNumber[k]=sc.nextInt();
System.out.println("enter out of 5 for rating");
Rate[k]=sc.next();
k++;
}
public String getDetails(){
System.out.println("Input company name to get its details");
String name2=sc.next();
for(int i=0;i<=(compName.length());i++){
if(name2==compName[i])
return compName[i]+" "+compNumber[i]+" "+Rate[i]+" rating";
}
}
public int getContact(){
System.out.println("Enter name of the company to get contact number");
String name1=sc.nextLine();
for(int i=0;i<=compName.length();i++){
if(name1==compName[i])
return compNumber[i];
}
}
}
Errors:error ';' expected Dir() throws RemoteException
cannot find symbol for(int i=0;i<=compName.length();i++)
symbol:method.length
error:incompatible types
location:return compNumber
required int found String
************SOLVED ERRORS OF THE ABOVE CODE*************
public class Client{
public static void main(String args[]){
try{
DirInterface st=(DirInterface)Naming.lookup("rmi://"+args[0]+"/AddService");
st.addDetails();
String det=st.getDetails();
System.out.println(det);
String xx=st.getContact();
System.out.println(xx);
}catch(Exception e){
System.out.println(e);
}
}
ERRORS:In Client class
Illegal start of type try{
expected ';'
Identifier expected
st.addDetails();
sopln(det);
catch}(Exception e){}
class,interface or enum expected