From be36b9277a2b919acefa9589f8bec47477abe408 Mon Sep 17 00:00:00 2001 From: aleksey_brehin Date: Mon, 25 Jul 2022 00:36:09 +0300 Subject: [PATCH 1/2] Renamed a file --- pro/sky/java/course1/homework6/Homework6.java | 126 ++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 pro/sky/java/course1/homework6/Homework6.java diff --git a/pro/sky/java/course1/homework6/Homework6.java b/pro/sky/java/course1/homework6/Homework6.java new file mode 100644 index 0000000..34a172e --- /dev/null +++ b/pro/sky/java/course1/homework6/Homework6.java @@ -0,0 +1,126 @@ +package pro.sky.java.course1.homework6; + +import java.time.LocalDate; +import java.util.Arrays; +import java.util.Scanner; + +public class Homework6 { + public static void checkYear(int year) { + if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) { + System.out.printf("%d is a leap year\n", year); + } else { + System.out.printf("%d is not a leap year\n", year); + } + } + + public static void checkOS(int deviceYear, int clientOS) { + int currentYear = LocalDate.now().getYear(); + if (clientOS == 1) { + if (deviceYear < currentYear) { + System.out.println("Install the lite-version for iOS at the link"); + } else if (deviceYear == currentYear) { + System.out.println("Install the full-version for iOS at the link"); + } else { + System.out.println("Incorrect input!"); + } + } else if (clientOS == 0) { + if (deviceYear < currentYear) { + System.out.println("Install the lite-version for Android at the link"); + } else if (deviceYear == currentYear) { + System.out.println("Install the full-version for Android at the link"); + } else { + System.out.println("Incorrect input!"); + } + } else { + System.out.println("Incorrect input!"); + } + } + + public static int calcDeliveryTime(int deliveryDistance) { + int deliveryTime = 1; + if (deliveryDistance > 20) { + deliveryTime++; + } + if (deliveryDistance > 60) { + deliveryTime++; + } + if (deliveryDistance <= 0) { + System.out.println("Incorrect input!"); + return 0; + } + return deliveryTime; + } + + public static void checkDoubles(String str) { + for (int i = 0; i < str.length() - 1; i++) { + if (str.charAt(i) == str.charAt(i + 1)) { + System.out.printf("Duplicate character '%c' found.\n", str.charAt(i)); + return; + } + } + System.out.println("Duplicate characters not found."); + } + + public static void reverseArrayOrder(int[] arr) { + for (int i = 0; i < arr.length / 2; i++) { + int t = arr[i]; + arr[i] = arr[arr.length - i - 1]; + arr[arr.length - i - 1] = t; + } + } + + public static int[] generateRandomArray() { + java.util.Random random = new java.util.Random(); + int[] arr = new int[30]; + for (int i = 0; i < arr.length; i++) { + arr[i] = random.nextInt(100_000) + 100_000; + } + return arr; + } + + public static double getAverage(int[] arr) { + double sum = getSum(arr); + double averageValue = sum / arr.length; + return averageValue; + } + + public static double getSum(int[] arr) { + int sum = 0; + for (int i = 0; i < arr.length; i++) { + sum += arr[i]; + } + return sum; + } + + + public static void main(String[] args) { + //task1 + Scanner input = new Scanner(System.in); + System.out.print("Enter the year: "); + int y = input.nextInt(); + checkYear(y); + //task2 + System.out.print("Enter the year of manufacture of the device: "); + int deviceYear = input.nextInt(); + System.out.print("Enter 0 if you have Android OS or 1 if iOS: "); + int deviceOS = input.nextInt(); + checkOS(deviceYear, deviceOS); + //task3 + System.out.print("Enter the distance: "); + int dist = input.nextInt(); + System.out.printf("Delivery will take %d days.\n", calcDeliveryTime(dist)); + //task4 + System.out.print("Enter some line: "); + String s = input.next(); + checkDoubles(s); + input.close(); + //task5 + int[] array = {7, 4, 5, 8, 1}; + reverseArrayOrder(array); + System.out.println("The reversed array looks like this: " + Arrays.toString(array)); + //task6 + int[] arr = generateRandomArray(); + double averageArr = getAverage(arr); + System.out.printf("The average expenditure was %.2f rubles. \n", averageArr); + } +} From 90b67e4ae2d1d9590d6bdd668592d333d9c2d43e Mon Sep 17 00:00:00 2001 From: aleksey_brehin Date: Mon, 25 Jul 2022 00:43:09 +0300 Subject: [PATCH 2/2] Renamed a file --- .../pro/sky/java/course1/homework6/Main.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename pro/sky/java/course1/homework6/Homework6.java => java/pro/sky/java/course1/homework6/Main.java (99%) diff --git a/pro/sky/java/course1/homework6/Homework6.java b/java/pro/sky/java/course1/homework6/Main.java similarity index 99% rename from pro/sky/java/course1/homework6/Homework6.java rename to java/pro/sky/java/course1/homework6/Main.java index 34a172e..49b2894 100644 --- a/pro/sky/java/course1/homework6/Homework6.java +++ b/java/pro/sky/java/course1/homework6/Main.java @@ -4,7 +4,7 @@ import java.util.Arrays; import java.util.Scanner; -public class Homework6 { +public class Main { public static void checkYear(int year) { if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) { System.out.printf("%d is a leap year\n", year);