VivianOlivian

Untitled

Sep 19th, 2019
99
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.sql.SQLOutput;
  2. import java.util.Scanner;
  3.  
  4. public class Calculator {
  5. public static void main(String[] args) {
  6. printToScreen("Старт программы", true);
  7. String numberOne = enterNum(true);
  8. String numberTwo = enterNum(true);
  9. printToScreen("Принял: ", false);
  10. printToScreen(numberOne, true);
  11. printToScreen("Принял: ", false);
  12. printToScreen(numberTwo, true);
  13. int firstNum = stringToInteger(numberOne);
  14. int secondNum = stringToInteger(numberTwo);
  15. int thirdNum = calcDifference(firstNum, secondNum);
  16. int fourthNum = calcSum(firstNum, secondNum);
  17. printToScreen("Результат: ", false);
  18. printToScreen(String.valueOf(thirdNum), true);
  19. printToScreen("Результат: ", false);
  20. printToScreen(String.valueOf(fourthNum), true);
  21. printToScreen("Конец программы", false);
  22. }
  23.  
  24. public static String enterNum(boolean isItNum) {
  25. Scanner scanner = new Scanner(System.in);
  26. printToScreen("Введите число:", false);
  27. String number = scanner.nextLine();
  28. while (!isItNum);{
  29. checkString(number);
  30. }{
  31. return number;}
  32. }
  33.  
  34. public static int stringToInteger(String stringData) {
  35. return Integer.parseInt(stringData);
  36. }
  37.  
  38. public static int calcDifference(int firstNumber, int secondNumber) {
  39. printToScreen("Начинаю считать", true);
  40. return firstNumber - secondNumber;
  41. }
  42.  
  43. public static int calcSum(int firstNumber, int secondNumber) {
  44. printToScreen("Начинаю считать", true);
  45. return firstNumber + secondNumber;
  46. }
  47.  
  48. public static void printToScreen(String abraCadaBra, boolean addNewLine) {
  49. if (addNewLine) {
  50. System.out.println(abraCadaBra);
  51. } else {
  52. System.out.print(abraCadaBra);
  53. }
  54. }
  55.  
  56. public static boolean checkString(String string) {
  57. try {
  58. Integer.parseInt(string);
  59. return true;
  60. } catch (IllegalArgumentException e) {
  61. return false;
  62. }
  63. }
  64. }
RAW Paste Data