Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- StepTracker StepTracker = new StepTracker(10000);
- Converter converter = new Converter(75, 50);
- while (true) {
- printMenu();
- int command = scanner.nextInt();
- if (command == 1) {
- System.out.println("Введите месяц (от 1 до 12)");
- printMonth();
- int month = inputMonth();
- System.out.println("Введите день (от 1 до 30)");
- int day = inputDay();
- System.out.println("Введите количество шагов");
- int stepCount = stepCount();
- StepTracker.saveStatistics(month, day, stepCount);
- } else if (command == 2) {
- System.out.println("Введите месяц для вывода статистики (от 1 до 12)");
- printMonth();
- int month = inputMonth();
- StepTracker.printStatistics(month);
- int maxStepsInMonth = StepTracker.calculateMaxStepsInMonth(month);
- double distance = converter.convertDistance(maxStepsInMonth);
- double kcalories = converter.convertCalories(maxStepsInMonth);
- System.out.println("Пройденная дистанция в месяце (километров) " + month + ": " + distance);
- System.out.println("Количество сожжённых килокалорий в месяце " + month + ": " + kcalories);
- StepTracker.printAverageStepsInMonth(month);
- StepTracker.printBestSeries(month);
- } else if (command == 3) {
- System.out.println("Введите новую цель по количеству шагов в день");
- int newTarget = newTarget();
- StepTracker.setTargetStep(newTarget);
- } else if (command == 0) {
- System.out.println("Выход");
- break;
- } else {
- System.out.println("Извините, такой команды пока нет.");
- }
- }
- }
- private static void printMonth() {
- String[] monthCount = {"Январь", "Февраль", "Март", "Апрель", "Май", "Июнь",
- "Июль", "Август", "Сентябрь", "Октябрь", "Ноябрь", "Декабрь"};
- for (int i = 0; i < monthCount.length; i++) {
- System.out.println((i + 1) + " " + monthCount[i]);
- }
- }
- private static void printMenu() {
- System.out.println("Что вы хотите сделать? ");
- System.out.println("1 - Ввести количество шагов за определённый день");
- System.out.println("2 - Напечатать статистику за определённый месяц");
- System.out.println("3 - Изменить цель по количеству шагов в день");
- System.out.println("0 - Выйти из приложения");
- }
- private static int inputMonth() {
- Scanner scanner = new Scanner(System.in);
- int month;
- while (true) {
- if (scanner.hasNextInt()) {
- month = scanner.nextInt();
- break;
- } else {
- System.out.println("Некорректный ввод, повторите попытку");
- scanner.next();
- }
- }
- return month;
- }
- private static int inputDay() {
- Scanner scanner = new Scanner(System.in);
- int day;
- while (true) {
- if (scanner.hasNextInt()) {
- day = scanner.nextInt();
- break;
- } else {
- System.out.println("Некорректный ввод, повторите попытку");
- scanner.next();
- }
- }
- return day;
- }
- private static int stepCount() {
- Scanner scanner = new Scanner(System.in);
- int stepCount;
- while (true) {
- if (scanner.hasNextInt()) {
- stepCount = scanner.nextInt();
- break;
- } else {
- System.out.println("Некорректный ввод, повторите попытку");
- scanner.next();
- }
- }
- return stepCount;
- }
- private static int newTarget() {
- Scanner scanner = new Scanner(System.in);
- int newTarget;
- while (true) {
- if (scanner.hasNextInt()) {
- newTarget = scanner.nextInt();
- break;
- } else {
- System.out.println("Некорректный ввод, повторите попытку");
- scanner.next();
- }
- }
- return newTarget;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement