/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package javaapplication70;

import java.util.Scanner;

/**
 *
 * @author joelx
 */
public class JavaApplication70 {

    /**
     * @param args the command line arguments
     */
    public static Scanner scan = new Scanner(System.in);
    public static int saisielargeur(int min){
        int x = 0;
        if(min % 2== 0){
            System.out.print(" entrez une largeur paire plus grande que " +min +": ");
             x =scan.nextInt();
            while(x<min || x%2 !=0){
                System.out.print("Erreur ! entrez une largeur paire plus grande que " +min +": ");
                x = scan.nextInt();
                
            }
        }else if( min % 2 != 0){
            System.out.print(" entrez une largeur impaire plus grande que " +min +": ");
             x =scan.nextInt();
            while(x <min || x %2==0 ){
                System.out.print("Erreur ! entrez une largeur impaire plus grande que " +min +": ");
                x = scan.nextInt();
                
            }
        }
        return x;
    }
    
    public static String saisietexte(){
        System.out.print("InTroduissez le texte à encadrer: ");
        return scan.nextLine();
    }
    
    public static void afficheLigneComplete(int lg) {
        System.out.print("+");
        for (int i = 2; i < lg; ++i)
            System.out.print("-");
        System.out.println("+");
    }
    
    public static void afficheBlancs(int nb) {
        for (int i = 0; i < nb; ++i)
            System.out.print(" ");
    }
    
    public static void affichetextecadre(String texte, int largeur) {
        afficheLigneComplete(largeur);
        System.out.print("|");
        int lgBlancs = (largeur - texte.length()) / 2 - 1;
        afficheBlancs(lgBlancs);
        
        System.out.print(texte);
        afficheBlancs(lgBlancs);
        System.out.println("|");
        afficheLigneComplete(largeur);
    }
    public static void main(String[] args) {
        String texte = saisietexte();
        int lg = saisielargeur(texte.length()+ 2);
        affichetextecadre(texte, lg);
        // TODO code application logic here
    }
    
}
