Social networks

Report a typo

There are three classes: an abstract class called SocialNetwork, and two concrete classes, Instagram and Facebook.
Your task is to implement the abstract class SocialNetwork with a template method called connect() and three abstract methods using the following algorithm:

  1. Log in
  2. Post a message
  3. Log out

Make Instagram and Facebook inherit from the SocialNetwork class and implement the methods according to the console output.

Sample Input 1:

instagram

Sample Output 1:

Log into Instagram
Post: Hello, Instagram!
Log out of Instagram

Sample Input 2:

facebook

Sample Output 2:

Log into Facebook
Post: Hello, Facebook!
Log out of Facebook
Write a program in Java 17
import java.util.Scanner;

abstract class SocialNetwork {

public void connect() {
// write your code here ...
}

// write your code here ...

}

class Instagram {
// write your code here ...
}


class Facebook {
// write your code here ...
}

// Do not change the code below
class Main {
public static void main(String[] args) {
final Scanner scanner = new Scanner(System.in);
final String type = scanner.nextLine();
scanner.close();
SocialNetwork network = null;
if ("facebook".equalsIgnoreCase(type)) {
network = new Facebook();
} else if ("instagram".equalsIgnoreCase(type)) {
network = new Instagram();
} else {
System.out.println("Error!");
System.exit(0);
}
___

Create a free account to access the full topic