-
Notifications
You must be signed in to change notification settings - Fork 0
/
CristinaCotetiuWeek2Homework.java
94 lines (75 loc) · 3.33 KB
/
CristinaCotetiuWeek2Homework.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package com.company;
import java.util.*;
public class CristinaCotetiuWeek2Homework {
public static void main(String[] args) {
System.out.println("Exercise 1");
exercise1();
System.out.println("Exercise 2");
exercise2();
System.out.println("Exercise 3");
exercise3();
System.out.println("Exercise 4");
exercise4w2();
}
public static void exercise1(){
String myFirstString = "Hello";
String mySecondString = "Salut";
String myConcatStrings = myFirstString.concat(mySecondString);
System.out.println("myFirstString is equal to mySecondString: " + myFirstString.equals(mySecondString));
System.out.println("These are my concatenated strings: " + myConcatStrings);
}
public static void exercise2(){
System.out.println("This string is a palindrome: " +PalindromeChecker.isPalindrome("madam"));
System.out.println("This string is a palindrome: " + PalindromeChecker.isPalindrome("test"));
}
public static void exercise3(){
String myEmptyString ="";
String[] myArrayString = new String[100];
int n=0;
List<String> firstName= Arrays.asList("Maximilian", "crIstina", "MAdalin",
"iOAna", "NicOleTa");
Character[] vowels = {'a', 'e', 'i', 'o', 'u'};
List<Character> vowelsList = Arrays.asList(vowels);
int i=0;
for(String name: firstName ){
if(vowelsList.contains(Character.toLowerCase(name.charAt(0)))){
firstName.set(i,name.toLowerCase());
myEmptyString +=name.toLowerCase();
} else {
firstName.set(i,name.toUpperCase());
myArrayString[n++] =name.toUpperCase();
}
if (name.toLowerCase().indexOf('x') >=0 || name.length()<3){
firstName.set(i,"skipped");
System.out.println(name + " " + firstName.get(i));
}
i++;
}
for (i=0; i<firstName.size(); i++){
System.out.print(firstName.get(i) + " ");
}
System.out.println();
System.out.println(myEmptyString);
for (i=0; i<n;i++){
System.out.print(myArrayString[i]+ "");
}
}
public static void exercise4w2(){
HashMap<String,String> contacts = new HashMap<String,String>();
contacts.put("Antonescu Anton", "[email protected]");
contacts.put("Pop Ion", "[email protected]");
contacts.put("Vuia Traian", "[email protected]");
contacts.put("James Bond", "[email protected]");
contacts.size();
System.out.println("This is the contacts map size:" + contacts.size());
contacts.containsKey("Pop Ion");
System.out.println("Is the 'Pop Ion' key present? " + contacts.containsKey("Pop Ion"));
contacts.containsValue("[email protected]");
System.out.println("Is the '[email protected]' present? " + contacts.containsValue("[email protected]"));
contacts.remove("Antonescu Anton", "[email protected]");
System.out.println("This is the contacts updated list: " + contacts);
Map<String,String> sortedContacts = new TreeMap<>(contacts);
System.out.println("This is the sorted list:");
sortedContacts.entrySet().forEach(System.out::println);
}
}