Advertisement
Guest User

Code

a guest
Apr 26th, 2018
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.04 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Phrase {
  4.  
  5.     private String phrase;
  6.  
  7.     public Phrase() {
  8.         this.phrase = "";
  9.     }
  10.  
  11.     public void saisir(){
  12.         Scanner sc = new Scanner(System.in);
  13.         System.out.println("Saisir la phrase");
  14.         this.phrase = sc.next();
  15.     }
  16.  
  17.     public void afficher(){
  18.         System.out.println("Phrase : " + this.phrase);
  19.     }
  20.  
  21.     public String miroir() {
  22.         String chaine = "";
  23.         for(int i = this.phrase.length()-1;i>=0;i--){
  24.             chaine += this.phrase.charAt(i);
  25.         }
  26.  
  27.         return chaine;
  28.     }
  29.  
  30.     public void palindrome() {
  31.         String chaine = this.miroir();
  32.         if(chaine.equals(this.phrase)){
  33.             System.out.println("C'est un palindrome");
  34.         } else {
  35.             System.out.println("Ce n'est pas un palindrome");
  36.         }
  37.     }
  38.  
  39.     public void crypter(int cle){
  40.         String chaine = "";
  41.  
  42.         for(int i = 0;i<=this.phrase.length() - 1;i++){
  43.                 chaine += (char)(this.phrase.charAt(i) + cle);
  44.             }
  45.  
  46.         System.out.println("Chaine cryptée  : " +chaine);
  47.  
  48.     }
  49.  
  50.     public void decrypter(int cle){
  51.         String chaine ="";
  52.         for(int i = 0;i<=this.phrase.length() - 1;i++){
  53.             chaine += (char)(this.phrase.charAt(i) - cle);
  54.         }
  55.  
  56.         System.out.println("Chaine décryptée  : " +chaine);
  57.     }
  58.  
  59.     public void gerer() {
  60.         Scanner sc = new Scanner(System.in);
  61.         int choix = 0;
  62.         do {
  63.             System.out.println("_______ MENU PHRASE ___________");
  64.             System.out.println("_1_ Saisir la phrase");
  65.             System.out.println("_2_ Afficher la phrase");
  66.             System.out.println("_3_ Miroir");
  67.             System.out.println("_4_ Palindrome");
  68.             System.out.println("_5_ Cryptage");
  69.             System.out.println("_6_ Decryptage");
  70.             System.out.println("_0_ Quitter");
  71.             System.out.println("Votre choix ->");
  72.             choix = sc.nextInt();
  73.             if(choix <= 6 && choix >= 0){
  74.                 switch(choix){
  75.                     case 1: this.saisir();break;
  76.                     case 2: this.afficher();break;
  77.                     case 3:
  78.                         System.out.println("Miroir " + this.miroir());
  79.                         break;
  80.                     case 4:this.palindrome();break;
  81.                     case 5: {
  82.                         int cle;
  83.                         System.out.println("Donner la cle :");
  84.                         cle = sc.nextInt();
  85.                         this.crypter(cle);
  86.                     }
  87.                         break;
  88.                     case 6: {
  89.                         int cle;
  90.                         System.out.println("Donner la cle :");
  91.                         cle = sc.nextInt();
  92.                         this.decrypter(cle);
  93.                     }
  94.                         break;
  95.                 }
  96.             } else {
  97.                 System.out.println("Choix incorrect");
  98.             }
  99.         } while(choix != 0);
  100.     }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement