Implement a Class instant InstantMessageAccount which represents an account in a
ID: 3651184 • Letter: I
Question
Implement a Class instant InstantMessageAccount which represents an account in an instant messagingserver such as AIM or Skype.Besides a username (here called screenName) to be set by the constructor,this class should internally keep track of the number of devices on which a user is logged in at the same (e.g. desktop computer ,tablet and a mobile phone).The constructor should initialise the private field loginCount with 0;a method login()(we dont care about passwords this time) should increment it by 1 and a method logout() should decrement it by 1.From the main method create an account into which you log in and out several times and print the respective login counts
Explanation / Answer
class InstantMessageAccount
{
private String username;
private int loginCount;
InstantMessageAccount()
{
loginCount=0;
}
public void login()
{
loginCount++;
}
public void logout()
{
loginCount--;
}
public int getLoginCount()
{
return loginCount;
}
public static void main(String args[])
{
InstantMessageAccount im=new InstantMessageAccount();
im.login();
im.login();
im.login();
im.login();
im.login();
System.out.println("The login count after 5 logins is: "+im.getLoginCount());
im.logout();
im.logout();
System.out.println("The login count after 2 logouts is: "+im.getLoginCount());
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.