-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/review #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| package pro.sky.java.course1.homework6; | ||
|
|
||
| import java.time.LocalDate; | ||
| import java.util.Arrays; | ||
| import java.util.Scanner; | ||
|
|
||
| public class Main { | ||
| public static void checkYear(int year) { | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. наименование |
||
| 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) { | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. предлагаю выделить из данного метода два метода:
а в основной метод передавать результат выполнения предыдущих двух и печатать информацию через из плюсов- уходим от вложенности if-else.
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. также нужно переименовать метод т.к. данное название не совсем отображает то, что делает метод |
||
| int currentYear = LocalDate.now().getYear(); | ||
| if (clientOS == 1) { | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. вынести в константы значения, которые отвечают за определение OS |
||
| 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) { | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. условия >20 и >60 перекрывают друг-друга, соответственно |
||
| deliveryTime++; | ||
| } | ||
| if (deliveryDistance <= 0) { | ||
| System.out.println("Incorrect input!"); | ||
| return 0; | ||
| } | ||
| return deliveryTime; | ||
| } | ||
|
|
||
| public static void checkDoubles(String str) { | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. предлагаю переименовать метод в checkDuplicateCharacter |
||
| 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) { | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. сумма целых чисел не может быть вещественным числом. возвращаемым значением должен быть |
||
| int sum = 0; | ||
| for (int i = 0; i < arr.length; i++) { | ||
| sum += arr[i]; | ||
| } | ||
| return sum; | ||
| } | ||
|
|
||
|
|
||
| public static void main(String[] args) { | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. перенести данный метод в начало класса, так будет проще отследить что делает данный класс
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. блоки(таски) предлагаю вынести в отдельные методы |
||
| //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); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/* <Что делает класс>
@autor Имя_Фамилия
*/