Skip to content

Toporov - 2 tasks completed #24

Open
aplih wants to merge 10 commits intodemologin:mainfrom
aplih:main
Open

Toporov - 2 tasks completed #24
aplih wants to merge 10 commits intodemologin:mainfrom
aplih:main

Conversation

@aplih
Copy link

@aplih aplih commented Sep 3, 2025

No description provided.

aplih added 10 commits August 22, 2025 10:34
Clarifying the encryption request, waiting fir keyboard input
ADD Caesar Cipher

in Caesar Cipher created only encrypt
FIX Caesar Cipher
FIX Caesar Cipher
FIX Caesar Cipher
ADD FileHandler
ADD UserInterface
FIX FileHandler
FIX UserInterface
FIX UserInterface
Copy link
Owner

@demologin demologin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Более менее аккуратно, но методов всего два, у основной массы их три, так что оценка C, но в целом код неплох. Будь его побольше, поставил бы B


public static String encrypt(String text, int shift) {

//создание пустой строки для сохранения результата
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

комментарии лучше оформлять в формате javadoc и не по русски а english (будет один индус в команде и придется все переводить для него, так что лучше сразу на english). Но у нас можно и на русском, просто привычка плохая )

boolean found = false;

//берем текущий символ из строки
char currentChar = text.charAt(i);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут весь текст целиком будет нужен и будет ограничение (по размеру кучи), а если бы посимвольно обрабатывать из потока в поток, то ограничений бы не было. Не так важно, но если бы это было серверное приложение то было бы очень важно - там памяти обычно сильно меньше


public class MainApp {
public static void main(String[] args) {
UserInterface ui = new UserInterface();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Имена лучше писать полностью: userInterface (ui - тут еще можно догадаться) fileHandler (а вот это fh - уже мало кто поймет)

}

// Если результат нужно сохранить в файл
if (mode == 1) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это магия. Что такое 1? Почему не 10 или не 100 или не 2? Нужна константа с понятным именем

import java.util.Scanner;

public class UserInterface {
Scanner scanner = new Scanner(System.in);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А что с модификаторами доступа? packege-private - это самый редкий вариант. Лучше явно все указать.

System.out.println("Choose an encryption, method: \n 1. Encrypt \n 2. Decrypt \n 3. BruteForce");
try {
int choice = Integer.parseInt(scanner.nextLine());
if (choice == 1 || choice == 2) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Константы с понятными именами, а не 1 и 2

return choice;
} else {
// если число некорректно
System.out.println("Please enter the correct value (1 or 2).");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

И тут их тоже надо использовать. Не надо хардкодить 1 и 2

}
// Ловим ошибку, если введено не число
} catch (NumberFormatException e) {
System.out.println("Invalid input. Please enter a number.");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ой нет. e терять нельзя. Его или выводят или логируют. Но не "теряют" никогда.

try {
return Integer.parseInt(scanner.nextLine());
} catch (NumberFormatException e) {
System.out.println("Invalid input. Please enter a number.");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

то же

System.out.println("Do you want to work with a file or a console? \n 1. File \n 2. Console");
try {
int mode = Integer.parseInt(scanner.nextLine());
if (mode == 1 || mode == 2 ) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

было выше

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants