Advertisement
icatalin

JAVA LAB 6

Mar 26th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.10 KB | None | 0 0
  1. Exercise 12  
  2. The Captain Crunch decoder ring works by taking each letter in a string and adding 13 to it. For example, ’a’ becomes ’n’ and ’b’ becomes ’o’. The letters “wrap around” at the end, so ’z’ becomes ’m’.
  3. Write a method that takes a String and that returns a new String containing the encoded version. You should assume that the String contains upper and lower case letters, and spaces, but no other punctuation. Lower case letters should be tranformed into other lower case letters; upper into upper. You should not encode the spaces.
  4. Generalize the Captain Crunch method so that instead of adding 13 to the letters, it adds any given amount. Now you should be able to encode things by adding 13 and decode them by adding -13. Try it.
  5.  
  6. //metoda fara StringBuilder
  7.  
  8. public class Main {
  9.  
  10.     public static void main(String[] args) {
  11.         String sir = "az";
  12.  
  13.         System.out.println(EncodeString(sir));
  14.  
  15.     }
  16.  
  17.  
  18.     public static String EncodeString (String sir){
  19.  
  20.  
  21.         String sirNou = "";
  22.  
  23.         for (int i = 0; i < sir.length(); i++){
  24.             char character = sir.charAt(i);
  25.  
  26.             int ascii = (int) character;
  27.  
  28.             if (ascii >= 97 && ascii <= 122)
  29.                 if (ascii + 13 > 122)
  30.                     ascii = 97 + ((ascii + 12) - 122);
  31.                 else
  32.                     ascii += 13;
  33.  
  34.             if (ascii >= 1 && ascii <= 26)
  35.                 if (ascii + 13 > 26)
  36.                     ascii = 1 + ((ascii + 12) - 26);
  37.                 else
  38.                     ascii += 13;
  39.  
  40.             character = (char) ascii;
  41.  
  42.             sirNou = sirNou + character;
  43.  
  44.             System.out.println(character);
  45.         }
  46.  
  47.         return sirNou;
  48.     }
  49.  
  50. }
  51.  
  52.  
  53. //metoda cu StringBuilder
  54.  
  55. // de terminat cu stringbuilder
  56.  
  57.  
  58. //TEMA pt 0.5 pcte la laborator, de facut pana peste 2 saptamani, de trimis pe mail
  59.  
  60. INTERFETE
  61. Coadă – generică+iterabilă         
  62. Scrieţi o clasă pentru o coadă (memorată înlănţuit) cu metode pentru operaţiile de bază: adăugare, eliminare, interogarea elementului curent, toString ( https://docs.oracle.com/javase/8/docs/api/java/util/Queue.html şi https://docs.oracle.com/javase/8/docs/api/java/util/ArrayDeque.html ); metodele se vor numi ca în interfaţa Queue din Java.
  63. Modificaţi clasa de coadă din tema trecută astfel încât să devină generică și iterabilă.  Folosind această clasă creaţi o coadă de şiruri de caractere, o coadă de întregi şi o coadă de cozi de numere întregi. Adăugaţi elemente noi şi ştergeţi elemente din aceste cozi.
  64. Adăugaţi în clasă şi o metodă pentru accesarea elementului de pe poziţia i.
  65.  
  66.  
  67. //MAVEN: folosim chestia asta pentru Maven: https://github.com/karlamaria100/CRM-Server/blob/master/pom.xml
  68. modificam cateva chestii in el
  69.  
  70. exemplu pt mail: https://mvnrepository.com/artifact/javax.mail/mail/1.4
  71.  
  72. pentru baza de date: https://github.com/karlamaria100/CRM-Server/blob/master/src/pao/dao/DataBaseConnection.java
  73.  
  74. model proiect: https://github.com/karlamaria100/CRM-Server
  75.  
  76. MY SQL + XAMPP
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement