Monday, June 12, 2017

Group Name Change In ChatApps

Tags

Following Code will give u a small idea how that change takes place:

Code:


public class User {
    int i;
String name;
long mobile;
Group[] g=new Group[10];

User(){   //Default Constructor
i=0;
name="No Name";
mobile=0000000000;
}

User(String n,long m){   //Parameterized Constructor
i=0;
name=n;
mobile=m;
}

void createGroup(String gn)
{
   g[i++]=new Group(gn,this);
}
    
void changeGname(String gn,int i)
{
g[i].Gname=gn;
}
}


public class User {
    int i;
String name;
long mobile;
Group[] g=new Group[10];
User(){   //Default Constructor
i=0;
name="No Name";
mobile=0000000000;
}
User(String n,long m){   //Parameterized Constructor
i=0;
name=n;
mobile=m;
}
void createGroup(String gn)
{
   g[i++]=new Group(gn,this);
}
    
void changeGname(String gn,int i)
{
g[i].Gname=gn;
}
}


public class Main {

public static void main(String[] nt) {
User u1=new User("Dishant",9023074222l);
User u2=new User("Garvit",8284010455l);
User u3=new User("Piyush",9815445194l);
User u4=new User("Nikhil",9815215752l);
User u5=new User("Navneet",9888321686l);
u1.createGroup("Brothers");
User[] x={u2,u3,u4,u5};
u1.g[0].addUsers(x);
u4.g[0].showGname();
u1.changeGname("For", 0);
u2.g[0].showGname();
u2.changeGname("Life", 0);
u5.g[0].showGname();
u3.changeGname("Yeahhh", 0);
u1.g[0].showGname();
System.out.println("------------------");
u3.g[0].showUsers();
}

}

Output::