Advertisement
_ums_

1 Sprint - Main

Feb 2nd, 2022
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.07 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.  
  5.     public static void main(String[] args) {
  6.  
  7.         Scanner scanner = new Scanner(System.in);
  8.         StepTracker StepTracker = new StepTracker(10000);
  9.         Converter converter = new Converter(75, 50);
  10.  
  11.         while (true) {
  12.             printMenu();
  13.  
  14.             int command = scanner.nextInt();
  15.  
  16.             if (command == 1) {
  17.                 System.out.println("Введите месяц (от 1 до 12)");
  18.                 printMonth();
  19.                 int month = inputMonth();
  20.                 System.out.println("Введите день (от 1 до 30)");
  21.                 int day = inputDay();
  22.                 System.out.println("Введите количество шагов");
  23.                 int stepCount = stepCount();
  24.                 StepTracker.saveStatistics(month, day, stepCount);
  25.             } else if (command == 2) {
  26.                 System.out.println("Введите месяц для вывода статистики (от 1 до 12)");
  27.                 printMonth();
  28.                 int month = inputMonth();
  29.                 StepTracker.printStatistics(month);
  30.                 int maxStepsInMonth = StepTracker.calculateMaxStepsInMonth(month);
  31.                 double distance = converter.convertDistance(maxStepsInMonth);
  32.                 double kcalories = converter.convertCalories(maxStepsInMonth);
  33.                 System.out.println("Пройденная дистанция в месяце (километров) " + month + ": " + distance);
  34.                 System.out.println("Количество сожжённых килокалорий в месяце " + month + ": " + kcalories);
  35.                 StepTracker.printAverageStepsInMonth(month);
  36.                 StepTracker.printBestSeries(month);
  37.             } else if (command == 3) {
  38.                 System.out.println("Введите новую цель по количеству шагов в день");
  39.                 int newTarget = newTarget();
  40.                 StepTracker.setTargetStep(newTarget);
  41.             } else if (command == 0) {
  42.                 System.out.println("Выход");
  43.                 break;
  44.             } else {
  45.                 System.out.println("Извините, такой команды пока нет.");
  46.             }
  47.         }
  48.     }
  49.  
  50.     private static void printMonth() {
  51.         String[] monthCount = {"Январь", "Февраль", "Март", "Апрель", "Май", "Июнь",
  52.                 "Июль", "Август", "Сентябрь", "Октябрь", "Ноябрь", "Декабрь"};
  53.         for (int i = 0; i < monthCount.length; i++) {
  54.             System.out.println((i + 1) + " " + monthCount[i]);
  55.         }
  56.     }
  57.  
  58.     private static void printMenu() {
  59.         System.out.println("Что вы хотите сделать? ");
  60.         System.out.println("1 - Ввести количество шагов за определённый день");
  61.         System.out.println("2 - Напечатать статистику за определённый месяц");
  62.         System.out.println("3 - Изменить цель по количеству шагов в день");
  63.         System.out.println("0 - Выйти из приложения");
  64.     }
  65.  
  66.     private static int inputMonth() {
  67.         Scanner scanner = new Scanner(System.in);
  68.         int month;
  69.         while (true) {
  70.             if (scanner.hasNextInt()) {
  71.                 month = scanner.nextInt();
  72.                 break;
  73.             } else {
  74.                 System.out.println("Некорректный ввод, повторите попытку");
  75.                 scanner.next();
  76.             }
  77.         }
  78.         return month;
  79.     }
  80.  
  81.     private static int inputDay() {
  82.         Scanner scanner = new Scanner(System.in);
  83.         int day;
  84.         while (true) {
  85.             if (scanner.hasNextInt()) {
  86.                 day = scanner.nextInt();
  87.                 break;
  88.             } else {
  89.                 System.out.println("Некорректный ввод, повторите попытку");
  90.                 scanner.next();
  91.             }
  92.         }
  93.         return day;
  94.     }
  95.  
  96.     private static int stepCount() {
  97.         Scanner scanner = new Scanner(System.in);
  98.         int stepCount;
  99.         while (true) {
  100.             if (scanner.hasNextInt()) {
  101.                 stepCount = scanner.nextInt();
  102.                 break;
  103.             } else {
  104.                 System.out.println("Некорректный ввод, повторите попытку");
  105.                 scanner.next();
  106.             }
  107.         }
  108.         return stepCount;
  109.     }
  110.  
  111.     private static int newTarget() {
  112.         Scanner scanner = new Scanner(System.in);
  113.         int newTarget;
  114.         while (true) {
  115.             if (scanner.hasNextInt()) {
  116.                 newTarget = scanner.nextInt();
  117.                 break;
  118.             } else {
  119.                 System.out.println("Некорректный ввод, повторите попытку");
  120.                 scanner.next();
  121.             }
  122.         }
  123.         return newTarget;
  124.     }
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement