Created
May 23, 2017 07:00
-
-
Save fermopili/687b4bce30a433ef7cee6cc5095d498f to your computer and use it in GitHub Desktop.
com.javarush.task.task38.task3801 Исправь ошибки в коде
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javarush.task.task38.task3801; | |
public class NameChecker { | |
private static final int MAX_NUMBER_OF_CHARACTERS = 100500; | |
public static int getNumberOfCharacters(String name) throws Exception { | |
if (name == null) | |
throw new NameIsNullException(); | |
else if (name.isEmpty()) | |
throw new NameIsEmptyException(); | |
int length = name.length(); | |
if (length > MAX_NUMBER_OF_CHARACTERS) | |
throw new Exception("Слишком длинное имя"); | |
return length; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javarush.task.task38.task3801; | |
public class NameIsEmptyException extends Exception{ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javarush.task.task38.task3801; | |
public class NameIsNullException extends Exception{ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javarush.task.task38.task3801; | |
/* | |
Исправь ошибки в коде | |
*/ | |
public class Solution | |
{ | |
public static void main(String[] args) | |
{ | |
if (args.length > 0) | |
{ | |
try | |
{ | |
System.out.println ( "Имя содержит " + NameChecker.getNumberOfCharacters ( args[0] ) + " символов" ); | |
} | |
catch (NameIsNullException e) | |
{ | |
System.out.println ( "Ошибка: Имя не задано" ); | |
} | |
catch (NameIsEmptyException e) | |
{ | |
System.out.println ( "Ошибка: Имя пустое" ); | |
} | |
catch (Exception e) | |
{ | |
System.out.println ( e.toString ( ) ); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
taskKey="com.javarush.task.task38.task3801" | |
Исправь ошибки в коде | |
Исключения NameIsEmptyException и NameIsNullException должны быть checked. | |
Все типы исключений должны быть обработаны. | |
Реализацию методов main() и getNumberOfCharacters() не менять. | |
Требования: | |
1. При возникновении NameIsNullException на экран должна быть выведена строка: "Ошибка: Имя не задано". | |
2. При возникновении NameIsEmptyException на экран должна быть выведена строка: "Ошибка: Имя пустое". | |
3. При возникновении любого другого исключения на экран должна быть выведена строка возвращаемая методом toString этого исключения. | |
4. Если исключений не было, на экран должна быть выведена строка формата: "Имя содержит X символов", где X - количество символов в нулевом параметре переданном в метод main. | |
5. Класс NameIsEmptyException должен быть потомком класса Exception. | |
6. Класс NameIsNullException должен быть потомком класса Exception. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment