From 7181bbce98a846e0c378300bcd7efbf3b61655f2 Mon Sep 17 00:00:00 2001 From: "supra89kren@ya.ru" Date: Sun, 11 Oct 2015 19:44:04 +0300 Subject: [PATCH 1/4] finished . . . --- untitled/src/ua/jet/MainClass.java | 96 ++++++++++++++++++++++++++++++ untitled/untitled.iml | 11 ++++ 2 files changed, 107 insertions(+) create mode 100644 untitled/src/ua/jet/MainClass.java create mode 100644 untitled/untitled.iml diff --git a/untitled/src/ua/jet/MainClass.java b/untitled/src/ua/jet/MainClass.java new file mode 100644 index 0000000..3d72962 --- /dev/null +++ b/untitled/src/ua/jet/MainClass.java @@ -0,0 +1,96 @@ +package ua.jet; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.List; + +/** + * Created by Администратор on 11.10.2015. + */ +public class MainClass { + + public static String screenReader(String message){ + try { + System.out.println(message); + BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); + return bufferedReader.readLine(); + }catch (Exception e){ + return "Wrong value!!!"; + } + } + + public static void factorial(Integer numeral){ + + BigInteger factorial=BigInteger.valueOf(1); + if (numeral>=0){ + for (int i=1 ; i < numeral+1 ; i++) { + factorial=factorial.multiply(BigInteger.valueOf(i)); + } + System.out.println("Factorial for number - "+numeral+" is equal to - "+factorial.toString()); + } else if (numeral<0){ + System.out.println("For this number can not be counted factorial"); + } + + } + + public static void sequenceFibonachi(Integer numeral){ + if (numeral>0) { + List listFibonachi = new ArrayList(); + for (int i = 0; i < numeral; i++) { + if (i == 0||i==1) { + listFibonachi.add (BigInteger.valueOf(1)); + }else { + listFibonachi.add(listFibonachi.get(i-2).add(listFibonachi.get(i - 1))); + } + } + for (BigInteger elementFibonachi:listFibonachi){ + System.out.print(elementFibonachi.toString() + " "); + } + }else { + System.out.println("Wrong value!!!"); + } + } + + public static void numberWordConverter(Integer numeral){ + List wordsList = new ArrayList(10); + wordsList.add("Zero"); + wordsList.add("One"); + wordsList.add("Two"); + wordsList.add("Three"); + wordsList.add("Four"); + wordsList.add("Five"); + wordsList.add("Six"); + wordsList.add("Seven"); + wordsList.add("Eight"); + wordsList.add("Nine"); + + try{ + System.out.println(wordsList.get(numeral)); + }catch (Exception e){ + System.out.println("This is not numeral. . . . "); + } + + } + + public static void main(String[] args) { + + try { + Integer numeralFromScreen = Integer.parseInt(screenReader("Choose :\n1.Factorial\n2.Sequence of Fibonachi\n3.Write a word for your numeral")); + switch (numeralFromScreen){ + case 1: factorial(Integer.parseInt(screenReader("Enter number :"))); + break; + case 2: sequenceFibonachi(Integer.parseInt(screenReader("How many numbers from sequence you want to see?"))); + break; + case 3: numberWordConverter(Integer.parseInt(screenReader("Enter your numeral:"))); + break; + + } + + }catch (Exception e){ + System.out.println("Wrong value \n"+ e.toString()); + } + + } +} diff --git a/untitled/untitled.iml b/untitled/untitled.iml new file mode 100644 index 0000000..37cc804 --- /dev/null +++ b/untitled/untitled.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file From 35700893d4c1c9ae75bfede16129444eb7b8909d Mon Sep 17 00:00:00 2001 From: AlexanderSk Date: Sun, 11 Oct 2015 20:04:35 +0300 Subject: [PATCH 2/4] finished . . . --- untitled/src/ua/jet/MainClass.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/untitled/src/ua/jet/MainClass.java b/untitled/src/ua/jet/MainClass.java index 3d72962..f30ee6e 100644 --- a/untitled/src/ua/jet/MainClass.java +++ b/untitled/src/ua/jet/MainClass.java @@ -17,7 +17,7 @@ public static String screenReader(String message){ BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); return bufferedReader.readLine(); }catch (Exception e){ - return "Wrong value!!!"; + return "Wrong value!!!!"; } } From 3c20ad8b23fbc2c9b61aedf7ac2d6479950d7bf9 Mon Sep 17 00:00:00 2001 From: "supra89kren@ya.ru" Date: Sun, 11 Oct 2015 20:14:14 +0300 Subject: [PATCH 3/4] edit swich:case construction . Now it works correct. --- untitled/src/ua/jet/MainClass.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/untitled/src/ua/jet/MainClass.java b/untitled/src/ua/jet/MainClass.java index f30ee6e..8029179 100644 --- a/untitled/src/ua/jet/MainClass.java +++ b/untitled/src/ua/jet/MainClass.java @@ -6,9 +6,7 @@ import java.util.ArrayList; import java.util.List; -/** - * Created by Администратор on 11.10.2015. - */ + public class MainClass { public static String screenReader(String message){ @@ -74,7 +72,7 @@ public static void numberWordConverter(Integer numeral){ } - public static void main(String[] args) { + public static void main(String[] args ) { try { Integer numeralFromScreen = Integer.parseInt(screenReader("Choose :\n1.Factorial\n2.Sequence of Fibonachi\n3.Write a word for your numeral")); @@ -83,9 +81,10 @@ public static void main(String[] args) { break; case 2: sequenceFibonachi(Integer.parseInt(screenReader("How many numbers from sequence you want to see?"))); break; - case 3: numberWordConverter(Integer.parseInt(screenReader("Enter your numeral:"))); + case 3: numberWordConverter(Integer.parseInt(screenReader("Enter your numeral :"))); break; - + default: + System.out.println("wrong value!!!"); } }catch (Exception e){ From 05e9a5eb9283284da36665e477f7f478d0cae42c Mon Sep 17 00:00:00 2001 From: "supra89kren@ya.ru" Date: Mon, 12 Oct 2015 20:14:12 +0300 Subject: [PATCH 4/4] edit swich:case construction . Now it works correct. --- untitled/src/ua/jet/MainClass.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/untitled/src/ua/jet/MainClass.java b/untitled/src/ua/jet/MainClass.java index 8029179..0b5f5cd 100644 --- a/untitled/src/ua/jet/MainClass.java +++ b/untitled/src/ua/jet/MainClass.java @@ -72,7 +72,7 @@ public static void numberWordConverter(Integer numeral){ } - public static void main(String[] args ) { + public static void main(String[] args){ try { Integer numeralFromScreen = Integer.parseInt(screenReader("Choose :\n1.Factorial\n2.Sequence of Fibonachi\n3.Write a word for your numeral")); @@ -81,14 +81,14 @@ public static void main(String[] args ) { break; case 2: sequenceFibonachi(Integer.parseInt(screenReader("How many numbers from sequence you want to see?"))); break; - case 3: numberWordConverter(Integer.parseInt(screenReader("Enter your numeral :"))); + case 3: numberWordConverter(Integer.parseInt(screenReader("Enter your numeral:"))); break; default: System.out.println("wrong value!!!"); } }catch (Exception e){ - System.out.println("Wrong value \n"+ e.toString()); + System.out.println("Wrong value\n"+ e.toString()); } }