public class Encrypt { public static String encryptByVowels(String str) { int vowel = 0; for (int i = 0; i < str.length(); i++) { if (str.charAt(i) == 'a' || str.charAt(i) == 'e' || str.charAt(i) == 'i' || str.charAt(i) == 'o' || str.charAt(i) == 'u' || str.charAt(i) == 'A' || str.charAt(i) == 'E' || str.charAt(i) == 'I' || str.charAt(i) == 'O' || str.charAt(i) == 'U') { vowel++; } } StringBuilder strBuilder = new StringBuilder(); char c = 0; for (int i = 0; i < str.length(); i++) { if (str.charAt(i) == 32) { strBuilder.append(" "); } else { if ((str.charAt(i) + vowel) > 90 && (str.charAt(i) + vowel) < 97) { c = (char) (96 + ((str.charAt(i) + vowel) % 90)); } else if ((str.charAt(i) + vowel) > 122) { c = (char) (64 + ((str.charAt(i) + vowel) % 122)); } else { c = (char) (str.charAt(i) + vowel); } strBuilder.append(c); } } return strBuilder.toString(); } }
- public class Encrypt {
- public static String encryptByVowels(String str) {
- int vowel = 0;
- for (int i = 0; i < str.length(); i++) {
- if (str.charAt(i) == 'a' || str.charAt(i) == 'e' || str.charAt(i) == 'i' || str.charAt(i) == 'o'
- || str.charAt(i) == 'u' || str.charAt(i) == 'A' || str.charAt(i) == 'E' || str.charAt(i) == 'I'
- || str.charAt(i) == 'O' || str.charAt(i) == 'U') {
- vowel++;
- }
- }
- StringBuilder strBuilder = new StringBuilder();
- char c = 0;
- for (int i = 0; i < str.length(); i++) {
- if (str.charAt(i) == 32) {
- strBuilder.append(" ");
- } else {
- if ((str.charAt(i) + vowel) > 90 && (str.charAt(i) + vowel) < 97) {
strBuilder.append("a");- c = (char) (96 + ((str.charAt(i) + vowel) % 90));
- } else if ((str.charAt(i) + vowel) > 122) {
strBuilder.append("A");- c = (char) (64 + ((str.charAt(i) + vowel) % 122));
- } else {
strBuilder.append((char)(str.charAt(i) + vowel));- c = (char) (str.charAt(i) + vowel);
- }
- strBuilder.append(c);
- }
- }
- return strBuilder.toString();
- }
- }
public class Encrypt { public static String encryptByVowels(String str) { int vowel = 0; for (int i = 0; i < str.length(); i++) { if (str.charAt(i) == 'a' || str.charAt(i) == 'e' || str.charAt(i) == 'i' || str.charAt(i) == 'o' || str.charAt(i) == 'u' || str.charAt(i) == 'A' || str.charAt(i) == 'E' || str.charAt(i) == 'I' || str.charAt(i) == 'O' || str.charAt(i) == 'U') { vowel++; } } StringBuilder strBuilder = new StringBuilder(); for (int i = 0; i < str.length(); i++) { if (str.charAt(i) == 32) { strBuilder.append(" "); } else { if ((str.charAt(i) + vowel) > 90 && (str.charAt(i) + vowel) < 97) { strBuilder.append("a"); } else if ((str.charAt(i) + vowel) > 122) { strBuilder.append("A"); } else { strBuilder.append((char)(str.charAt(i) + vowel)); } } } return strBuilder.toString(); } }
- public class Encrypt {
- public static String encryptByVowels(String str) {
String newS = "";int cont = 0;for(char c: str.toLowerCase().toCharArray()) {if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')cont++;- int vowel = 0;
- for (int i = 0; i < str.length(); i++) {
- if (str.charAt(i) == 'a' || str.charAt(i) == 'e' || str.charAt(i) == 'i' || str.charAt(i) == 'o'
- || str.charAt(i) == 'u' || str.charAt(i) == 'A' || str.charAt(i) == 'E' || str.charAt(i) == 'I'
- || str.charAt(i) == 'O' || str.charAt(i) == 'U') {
- vowel++;
- }
- }
for(char c: str.toCharArray()) {int newChar = (int) c;if(c != ' '){newChar = c+cont;if(newChar > 90 && newChar < 97)newChar+=(97-newChar);if(newChar > 122) {newChar = 64 + newChar%122;if(newChar > 90 && newChar < 97)newChar+=(97-newChar);}}newS+=""+(char)newChar;- StringBuilder strBuilder = new StringBuilder();
- for (int i = 0; i < str.length(); i++) {
- if (str.charAt(i) == 32) {
- strBuilder.append(" ");
- } else {
- if ((str.charAt(i) + vowel) > 90 && (str.charAt(i) + vowel) < 97) {
- strBuilder.append("a");
- } else if ((str.charAt(i) + vowel) > 122) {
- strBuilder.append("A");
- } else {
- strBuilder.append((char)(str.charAt(i) + vowel));
- }
- }
- }
return newS;- return strBuilder.toString();
- }
- }
import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.RepeatedTest; import org.junit.jupiter.api.DisplayName; import java.util.Random; // TODO: Replace examples and use TDD by writing your own tests class SolutionTest { @Test void testWords() { assertEquals("PR", Encrypt.encryptByVowels("PR")); assertEquals("bc", Encrypt.encryptByVowels("ab")); } @Test void testWrap(){ assertEquals("ab", Encrypt.encryptByVowels("Za")); assertEquals("Ab", Encrypt.encryptByVowels("za")); } @Test void testEmptyOrBlank(){ assertEquals("", Encrypt.encryptByVowels("")); assertEquals(" ", Encrypt.encryptByVowels(" ")); } @Test void sentences(){ assertEquals("Mtqf vzj yfq", Encrypt.encryptByVowels("Hola que tal")); } @DisplayName("Random tests") @RepeatedTest(40) void randomTests() { Random rand = new Random(); String str = ""; for(int j = 0; j < rand.nextInt(1, 5); j++){ for(int i = 0; i < rand.nextInt(1, 100); i++){ int randomNumber = rand.nextInt(65, 122); if(randomNumber > 90 && randomNumber < 97) randomNumber+=(97-randomNumber); str+=""+(char)randomNumber; } str+=" "; } assertEquals(Encrypt.encryptByVowels(str.substring(0, str.length()-1)) ,sol(str.substring(0, str.length()-1))); } public static String sol(String s) { return s; } }
- import org.junit.jupiter.api.Test;
- import static org.junit.jupiter.api.Assertions.assertEquals;
- import org.junit.jupiter.api.RepeatedTest;
- import org.junit.jupiter.api.DisplayName;
- import java.util.Random;
- // TODO: Replace examples and use TDD by writing your own tests
- class SolutionTest {
- @Test
- void testWords() {
- assertEquals("PR", Encrypt.encryptByVowels("PR"));
- assertEquals("bc", Encrypt.encryptByVowels("ab"));
assertEquals("", Encrypt.encryptByVowels(""));- }
- @Test
- void testWrap(){
- assertEquals("ab", Encrypt.encryptByVowels("Za"));
- assertEquals("Ab", Encrypt.encryptByVowels("za"));
- }
- @Test
- void testEmptyOrBlank(){
- assertEquals("", Encrypt.encryptByVowels(""));
- assertEquals(" ", Encrypt.encryptByVowels(" "));
- }
- @Test
- void sentences(){
- assertEquals("Mtqf vzj yfq", Encrypt.encryptByVowels("Hola que tal"));
- }
- @DisplayName("Random tests")
- @RepeatedTest(40)
- void randomTests() {
- Random rand = new Random();
- String str = "";
- for(int j = 0; j < rand.nextInt(1, 5); j++){
- for(int i = 0; i < rand.nextInt(1, 100); i++){
- int randomNumber = rand.nextInt(65, 122);
- if(randomNumber > 90 && randomNumber < 97)
- randomNumber+=(97-randomNumber);
- str+=""+(char)randomNumber;
- }
- str+=" ";
- }
- assertEquals(Encrypt.encryptByVowels(str.substring(0, str.length()-1)) ,sol(str.substring(0, str.length()-1)));
- }
public static String sol(String str) {String newS = "";int cont = 0;for(char c: str.toLowerCase().toCharArray()) {if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')cont++;}for(char c: str.toCharArray()) {int newChar = (int) c;if(c != ' '){newChar = c+cont;if(newChar > 90 && newChar < 97)newChar+=(97-newChar);if(newChar > 122) {newChar = 64 + newChar%122;if(newChar > 90 && newChar < 97)newChar+=(97-newChar);}}newS+=""+(char)newChar;}return newS;- public static String sol(String s) {
- return s;
- }
- }
import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.RepeatedTest; import org.junit.jupiter.api.DisplayName; import java.util.Random; // TODO: Replace examples and use TDD by writing your own tests class SolutionTest { @Test void testSomething() { assertEquals("PR", Encrypt.encryptByVowels("PR")); assertEquals("bc", Encrypt.encryptByVowels("ab")); assertEquals("", Encrypt.encryptByVowels("")); } @DisplayName("Random tests") @RepeatedTest(40) void randomTests() { Random rand = new Random(); String str = ""; for(int i = 0; i < rand.nextInt(1, 100); i++){ int randomNumber = rand.nextInt(65, 122); if(randomNumber > 90 && randomNumber < 97) randomNumber+=(97-randomNumber); str+=""+(char)randomNumber; } assertEquals(Encrypt.encryptByVowels(str) ,sol(str)); } public static String sol(String s) { return s; } }
- import org.junit.jupiter.api.Test;
- import static org.junit.jupiter.api.Assertions.assertEquals;
- import org.junit.jupiter.api.RepeatedTest;
- import org.junit.jupiter.api.DisplayName;
- import java.util.Random;
- // TODO: Replace examples and use TDD by writing your own tests
- class SolutionTest {
- @Test
- void testSomething() {
// assertEquals("expected", "actual");- assertEquals("PR", Encrypt.encryptByVowels("PR"));
- assertEquals("bc", Encrypt.encryptByVowels("ab"));
- assertEquals("", Encrypt.encryptByVowels(""));
- }
- @DisplayName("Random tests")
- @RepeatedTest(40)
- void randomTests() {
- Random rand = new Random();
- String str = "";
- for(int i = 0; i < rand.nextInt(1, 100); i++){
- int randomNumber = rand.nextInt(65, 122);
- if(randomNumber > 90 && randomNumber < 97)
- randomNumber+=(97-randomNumber);
- str+=""+(char)randomNumber;
- }
- assertEquals(Encrypt.encryptByVowels(str) ,sol(str));
- }
- public static String sol(String s) {
- return s;
- }
- }
public class Encrypt() {
public static String encryptByVocals(String str) {
}
}
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
// TODO: Replace examples and use TDD by writing your own tests
class SolutionTest {
@Test
void testSomething() {
// assertEquals("expected", "actual");
}
}