Classe Principale
package social.network;
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
public class Principale {
    
    public static void main(String[] args) {
        Principale p = new Principale();
        p.inizio();
    }
    
    
    private void inizio(){
        boolean continua = true;
        Social social = new Social();
        while(continua){
            int scelta = this.schermoMenu();
            if(scelta == 0){
                System.out.println("Arrivederci");
                continua = false;
            }
            if(scelta == 1){
                Utente dati = this.leggiUtente(social);
                if(dati == null){
                    System.out.println("il nome utente è già presente");
                  
                }else{
                    social.aggiungi(dati);
                    System.out.println("utente aggiunto correttamente");
                }
                
            }
            if(scelta == 2){
                System.out.println("inserisci il nome utente che ha scritto il post");
                String nome = this.leggiStringaNonVuota();
                Utente utente = social.verificaNomeUtente(nome);
                if(utente == null ){
                    System.out.println("non esiste questo utente");
                }else{
                    Post post = this.leggiPost();
                    utente.aggiungi(post);
                    System.out.println("post aggiunto correttamente");
                }    
            }
            if(scelta == 3){
                List<Utente> elementi = social.verificaPost();
                Utente m = social.utenteGiovane(elementi);
                System.out.println(m.toString());
                
            }
            if(scelta == 4){
                System.out.println("inserisci il nome dell'utente");
                String nome = this.leggiStringaNonVuota();
                Utente m = social.verificaNomeUtente(nome);
                if(m == null){
                    System.out.println("l'utente non è presente, riprova");
                }else{
                    
                }
            }
            
        }
    }
    
    private Utente leggiUtente(Social social){
        System.out.println("inserisci il nome utente ");
        String nomeUtente = this.leggiStringaNonVuota();
        while(social.verificaNomeUtente(nomeUtente) != null){
            return null;
        }
        System.out.println("inserisci il nome");
        String nome = this.leggiStringaNonVuota();
        System.out.println("inserisci l'eta dell'utente");
        int eta = this.leggiIntero();
        return new Utente(nomeUtente, nome, eta);
    }
    
    private Post leggiPost(){
        System.out.println("inserisci il codice");
        String codice = this.leggiStringaNonVuota();
        System.out.println("inserisci testo ");
        String post = this.leggiStringaNonVuota();
        System.out.println("inserisci numero Like");
        int numeroLike = this.leggiIntero();
        return new Post(codice, post, numeroLike);
    }
    
    private int schermoMenu(){
        System.out.println("1) inserisci dati utente");
        System.out.println("2) inserisci Post");
        System.out.println("3) calcola utente più giovane e popolare");
        System.out.println("4) Post duplicati");
        System.out.println("0) Esci");
        System.out.print("inserisci la tua scelta: ");
        Scanner m = new Scanner(System.in);
        int scelta = m.nextInt();
        while(scelta < 0 || scelta > 4){
            System.out.println("Errore: scelta non valida ,riprova");
            scelta = m.nextInt();
        }
        return scelta;
        
    }
    
    private int leggiIntero(){
        Scanner m = new Scanner(System.in);
        int numero = m.nextInt();
        while(numero < 0){
            System.out.println("Errore riprova");
            numero = m.nextInt();
        }
        return numero;
    }
    
    private String leggiStringaNonVuota(){
        Scanner m = new Scanner(System.in);
        String stringa = m.next();
        while(stringa.trim().isEmpty()){
            System.out.println("la stringa non può essere vuota, riprova");
            stringa = m.next();
        }
        return stringa;
    }
}
Classe social
package social.network;
import java.util.List;
import java.util.ArrayList;
public class Social {
    
    private List<Utente> lista = new ArrayList<Utente>();
    
    public void aggiungi(Utente m){
        this.lista.add(m);
    }
    
    public Utente verificaNomeUtente(String nomeUtente){
        for(Utente m : this.lista){
            if(nomeUtente.equalsIgnoreCase(m.getNomeUtente())){
                return m;
            }
        }
        return null;
    } 
    
    public List<Utente> verificaPost(){
        List<Utente> l = new ArrayList<Utente>();
        for(Utente s : this.lista){
            if(s.verificaLike()){
                l.add(s);
            }
        }
        return l;
    }
    
    public Utente utenteGiovane(List<Utente> l){
        if(l.isEmpty()){
            throw new IllegalArgumentException("lista vuota");
        }
        Utente m = lista.get(0);
        for(Utente s : this.lista){
            if(m.getEta() > s.getEta()){
                m = s;
            }
            
        }
    return m;
    }
   
    
    
}
package social.network;
import java.util.List;
import java.util.ArrayList;
public class Utente {
    
    private String nomeUtente;
    private String nome;
    private int eta;
    private List<Post> lista = new ArrayList<Post>();
    
    public Utente(String nomeUtente,String nome,int eta){
        this.nomeUtente = nomeUtente;
        this.nome = nome;
        this.eta = eta;
        
    }
    
    public String getNomeUtente(){
        return this.nomeUtente;
    }
    
    @Override
    public String toString(){
        StringBuilder m = new StringBuilder();
        m.append("\nNome Utente: " + this.nomeUtente);
        m.append("\nNome: " + this.nome);
        m.append("\nEta: " +this.eta);
        return m.toString();
    }
    
    public void aggiungi(Post p){
        this.lista.add(p);
    }
    
    public int getEta(){
        return this.eta;
    }
    
    public boolean verificaLike(){
        for(Post m : this.lista){
            if(m.getNumeroLike() >= 1){
                return true;
            }
        }
        return false;
    }
    
    
}
package social.network;
public class Post {
    private String codice;
    private String testo;
    private int numeroLike;
    
    public Post(String codice,String testo,int numeroLike){
        this.codice = codice;
        this.numeroLike = numeroLike;
        this.testo = testo;
    }
    
    public int getNumeroLike(){
        return this.numeroLike;
    }
    
    public String getTesto(){
        return this.testo;
    }
}