Практика
This commit is contained in:
+1
-1
@@ -1,3 +1,3 @@
|
|||||||
enum Status {
|
enum Status {
|
||||||
DRAFT, REVIEW, APPROVED
|
LOW, MEDIUM, HIGH
|
||||||
}
|
}
|
||||||
+32
-21
@@ -1,33 +1,44 @@
|
|||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
public class TaskDemo {
|
public class TaskDemo {
|
||||||
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
String[][] menu = {
|
|
||||||
{"Профиль", "Настройки"},
|
int[] time = {20, 51, 55, 66, 45, 54};
|
||||||
{"Главная", "Каталог"},
|
System.out.println("Общее количество минут: " + calculateTotalMinutes(time));
|
||||||
{"Корзина", "Оплата"}
|
System.out.println("Среднее время просмотра: " + calculateTotalMinutes(time) / time.length);
|
||||||
};
|
|
||||||
String target = "Каталог";
|
System.out.println("Количество дней больше 50 минут :" + countLongSessions(time) + "дней");
|
||||||
System.out.println(java.util.Arrays.toString(masMenu(menu, target)));
|
System.out.println("Ваш статус: " + getUserStatus(countLongSessions(time)));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int[] masMenu(String[][] menu, String target) {
|
public static int calculateTotalMinutes(int[] time) {
|
||||||
if (menu.length == 0 || menu[0].length == 0) {
|
int days = 0;
|
||||||
return new int[]{-1, -1};
|
|
||||||
}else {
|
for (int i = 0; i < time.length; i++) {
|
||||||
for (int i = 0; i < menu.length; i++) {
|
days += time[i];
|
||||||
for (int j = 0; j < menu[0].length; j++) {
|
}
|
||||||
if (menu[i][j].equals(target)) {
|
return days;
|
||||||
return new int[]{i, j};
|
}
|
||||||
}
|
|
||||||
}
|
public static int countLongSessions(int[] time) {
|
||||||
|
int count = 0;
|
||||||
|
for (int i = 0; i < time.length; i++) {
|
||||||
|
if (time[i] > 50) {
|
||||||
|
count++;
|
||||||
}
|
}
|
||||||
}return new int[]{-1, -1};
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
public static Status getUserStatus(int count) {
|
||||||
|
switch (count) {
|
||||||
|
case 0, 1, 2 -> {return Status.LOW;}
|
||||||
|
case 3, 4, 5 -> {return Status.MEDIUM;}
|
||||||
|
default -> {return Status.HIGH;}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user