I am learning java and would like to create a very simple application but which uses SOLID principles.
The required functionality is: generate the alphabet with a possibility to select specific letters. For now there must be an option to select only even/odd letters but the project must be open for extra functionalities (which are unknown at the moment but may be defined in the near future).
I created a code but I got a feedback that my code is not using the Single Responsibility Principle. Could you please help me understand which part of my code is not in line with that principle and what can be done better?
abstract class Characters {
private ArrayList<Character> array;
public ArrayList<Character> getArray() {
return array;
}
public Characters() {
array = new ArrayList<>();
for (int i = 0; i < 26; i++) {
array.add((char) ('A' + i));
}
}
public abstract void getModifiedArray(String arg);
}
class CharactersParity extends Characters {
@Override
public void getModifiedArray(String arg) {
String arg2 = arg.trim().toLowerCase();
switch (arg2) {
case "even": {
for (char c : getArray()) {
if (c % 2 == 0) {
System.out.println(c);
}
}
}
break;
case "odd": {
for (char c : getArray()) {
if (c % 2 != 0) {
System.out.println(c);
}
}
}
break;
default:
System.out.println("wrong parameter");
}
}
}