Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Exercise 12
- 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’.
- 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.
- 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.
- //metoda fara StringBuilder
- public class Main {
- public static void main(String[] args) {
- String sir = "az";
- System.out.println(EncodeString(sir));
- }
- public static String EncodeString (String sir){
- String sirNou = "";
- for (int i = 0; i < sir.length(); i++){
- char character = sir.charAt(i);
- int ascii = (int) character;
- if (ascii >= 97 && ascii <= 122)
- if (ascii + 13 > 122)
- ascii = 97 + ((ascii + 12) - 122);
- else
- ascii += 13;
- if (ascii >= 1 && ascii <= 26)
- if (ascii + 13 > 26)
- ascii = 1 + ((ascii + 12) - 26);
- else
- ascii += 13;
- character = (char) ascii;
- sirNou = sirNou + character;
- System.out.println(character);
- }
- return sirNou;
- }
- }
- //metoda cu StringBuilder
- // de terminat cu stringbuilder
- //TEMA pt 0.5 pcte la laborator, de facut pana peste 2 saptamani, de trimis pe mail
- INTERFETE
- Coadă – generică+iterabilă
- 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.
- 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.
- Adăugaţi în clasă şi o metodă pentru accesarea elementului de pe poziţia i.
- //MAVEN: folosim chestia asta pentru Maven: https://github.com/karlamaria100/CRM-Server/blob/master/pom.xml
- modificam cateva chestii in el
- exemplu pt mail: https://mvnrepository.com/artifact/javax.mail/mail/1.4
- pentru baza de date: https://github.com/karlamaria100/CRM-Server/blob/master/src/pao/dao/DataBaseConnection.java
- model proiect: https://github.com/karlamaria100/CRM-Server
- MY SQL + XAMPP
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement