Learn constants, enum and switch
This commit is contained in:
+16
-10
@@ -1,18 +1,24 @@
|
|||||||
public class Main {
|
public class Main {
|
||||||
|
public static final int BASE_GRID = 8;
|
||||||
|
|
||||||
|
enum OrderStatus {
|
||||||
|
DRAFT,
|
||||||
|
PROCESSING,
|
||||||
|
DELIVERED
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
String name = "Евгений Селезнев";
|
OrderStatus currentStatus = OrderStatus.DRAFT;
|
||||||
U.pl(getAvatarInitials(name));
|
|
||||||
|
|
||||||
|
U.pl(getStatusColor(OrderStatus.DRAFT));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getAvatarInitials(String name) {
|
public static String getStatusColor(OrderStatus status) {
|
||||||
int firstLetterOfLastName = name.indexOf(" ") + 1;
|
return switch (status) {
|
||||||
String result = name.substring(0, 1) + name.substring(firstLetterOfLastName, firstLetterOfLastName + 1 );
|
case DRAFT -> "Серый";
|
||||||
return result.toUpperCase();
|
case PROCESSING -> "Желтый";
|
||||||
|
case DELIVERED -> "Зеленый";
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user