Skip to content

Instantly share code, notes, and snippets.

@Subuday77
Created August 5, 2020 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Subuday77/de1d77454d15e5016d2496a1f3ed24f7 to your computer and use it in GitHub Desktop.
Save Subuday77/de1d77454d15e5016d2496a1f3ed24f7 to your computer and use it in GitHub Desktop.
Rainbow Colors
package com.javarush.task.task03.task0315;
/*
Каждый охотник желает знать…
*/
import java.util.ArrayList;
import java.util.Arrays;
public class Solution {
public static void main(String[] args) {
String classes = Arrays.toString(Solution.class.getClasses());
String name = "";
ArrayList<String> colors = new ArrayList<>();
try {
while (true) {
colors.add(classes.substring(classes.indexOf("$") + 1, classes.indexOf(",")));
classes = classes.substring(classes.indexOf(",") + 1);
}
} catch (StringIndexOutOfBoundsException e) {
colors.add(classes.substring(classes.indexOf("$") + 1, classes.indexOf("]")));
}
for (int i = colors.size() - 1; i >= 0; --i) {
String color = colors.get(i);
switch (color) {
case "Red":
Red red = new Red();
break;
case "Orange":
Orange orange = new Orange();
break;
case "Yellow":
Yellow yellow = new Yellow();
break;
case "Green":
Green green = new Green();
break;
case "Blue":
Blue blue = new Blue();
break;
case "Indigo":
Indigo indigo = new Indigo();
break;
case "Violet":
Violet violet = new Violet();
break;
default:
break;
}
}
}
public static class Red {
public Red() {
System.out.println("Red");
}
}
public static class Orange {
public Orange() {
System.out.println("Orange");
}
}
public static class Yellow {
public Yellow() {
System.out.println("Yellow");
}
}
public static class Green {
public Green() {
System.out.println("Green");
}
}
public static class Blue {
public Blue() {
System.out.println("Blue");
}
}
public static class Indigo {
public Indigo() {
System.out.println("Indigo");
}
}
public static class Violet {
public Violet() {
System.out.println("Violet");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment