Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Phrase {
- private String phrase;
- public Phrase() {
- this.phrase = "";
- }
- public void saisir(){
- Scanner sc = new Scanner(System.in);
- System.out.println("Saisir la phrase");
- this.phrase = sc.next();
- }
- public void afficher(){
- System.out.println("Phrase : " + this.phrase);
- }
- public String miroir() {
- String chaine = "";
- for(int i = this.phrase.length()-1;i>=0;i--){
- chaine += this.phrase.charAt(i);
- }
- return chaine;
- }
- public void palindrome() {
- String chaine = this.miroir();
- if(chaine.equals(this.phrase)){
- System.out.println("C'est un palindrome");
- } else {
- System.out.println("Ce n'est pas un palindrome");
- }
- }
- public void crypter(int cle){
- String chaine = "";
- for(int i = 0;i<=this.phrase.length() - 1;i++){
- chaine += (char)(this.phrase.charAt(i) + cle);
- }
- System.out.println("Chaine cryptée : " +chaine);
- }
- public void decrypter(int cle){
- String chaine ="";
- for(int i = 0;i<=this.phrase.length() - 1;i++){
- chaine += (char)(this.phrase.charAt(i) - cle);
- }
- System.out.println("Chaine décryptée : " +chaine);
- }
- public void gerer() {
- Scanner sc = new Scanner(System.in);
- int choix = 0;
- do {
- System.out.println("_______ MENU PHRASE ___________");
- System.out.println("_1_ Saisir la phrase");
- System.out.println("_2_ Afficher la phrase");
- System.out.println("_3_ Miroir");
- System.out.println("_4_ Palindrome");
- System.out.println("_5_ Cryptage");
- System.out.println("_6_ Decryptage");
- System.out.println("_0_ Quitter");
- System.out.println("Votre choix ->");
- choix = sc.nextInt();
- if(choix <= 6 && choix >= 0){
- switch(choix){
- case 1: this.saisir();break;
- case 2: this.afficher();break;
- case 3:
- System.out.println("Miroir " + this.miroir());
- break;
- case 4:this.palindrome();break;
- case 5: {
- int cle;
- System.out.println("Donner la cle :");
- cle = sc.nextInt();
- this.crypter(cle);
- }
- break;
- case 6: {
- int cle;
- System.out.println("Donner la cle :");
- cle = sc.nextInt();
- this.decrypter(cle);
- }
- break;
- }
- } else {
- System.out.println("Choix incorrect");
- }
- } while(choix != 0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement