diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..477e576 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +GitAssignmentObserver \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..a55e7a1 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..ad36d52 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..3dd0b66 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..3000664 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,100 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1583172115957 + + + + + + + \ No newline at end of file diff --git a/GitAssignmentObserver.iml b/GitAssignmentObserver.iml new file mode 100644 index 0000000..26db12c --- /dev/null +++ b/GitAssignmentObserver.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/src/CircleArea.java b/src/CircleArea.java new file mode 100644 index 0000000..e0db006 --- /dev/null +++ b/src/CircleArea.java @@ -0,0 +1,14 @@ + +public class CircleArea implements ISubscriber { + @Override + public void notifySubscriber(String input) { + try { + double r = Double.parseDouble(input); + if(r >= 0) + System.out.println("The circle with radius = " + r + " , has area = " + (r*r*3.14)); + else System.out.println("Error , radius can't have negative value"); + } catch (Exception e) { + System.out.println("Error: " + e.getMessage()); + } + } +} diff --git a/src/CircleVolum.java b/src/CircleVolum.java new file mode 100644 index 0000000..6022ca0 --- /dev/null +++ b/src/CircleVolum.java @@ -0,0 +1,17 @@ +package com.company; + +public class CircleVolum implements ISubscriber { + @Override + public void notifySubscriber(String input) { + try { + double radius = Double.parseDouble(input); + System.out.println(calculateVolum(radius)); + } catch (Exception e) { + System.out.println("Error: " + e.getMessage()); + } + } + private double calculateVolum(double radius) + { + return radius * radius * radius * (4.0/3) * 3.14; + } +} diff --git a/src/Fibonacci.java b/src/Fibonacci.java new file mode 100644 index 0000000..2310c2e --- /dev/null +++ b/src/Fibonacci.java @@ -0,0 +1,19 @@ + +public class Fibonacci implements ISubscriber{ + + @Override + public void notifySubscriber(String input) + { + long n = Integer.parseInt(input); + long t1 = 0, t2 = 1; + for (int i = 1; i <= n; ++i) + { + System.out.print(t1 + " "); + + long sum = t1 + t2; + t1 = t2; + t2 = sum; + } + } + +} diff --git a/src/LucasSeries.java b/src/LucasSeries.java new file mode 100644 index 0000000..b26a657 --- /dev/null +++ b/src/LucasSeries.java @@ -0,0 +1,20 @@ +public class LucasSeries implements ISubscriber { + @Override + public void notifySubscriber(String input) { + try { + int LucasIndex = Integer.parseInt(input); + System.out.println("Lucas Number is: " + Lucas(LucasIndex)); + } catch (Exception e) { + System.out.println("Error: " + e.getMessage()); + } + } + + int Lucas(int idx) throws Exception { + if (idx <= 0) throw new Exception("Error: Lucas applied only for positive numbers."); + return Lucas(idx, 1, 2); // Lucas series 2 1 3 4 7 11 18 29 + } + + private int Lucas(int idx, int value, int previous) { + return (idx == 1 ? previous : Lucas(idx - 1, previous + value, value)); + } +} diff --git a/src/Main.java b/src/Main.java index 9b8c2b0..864a60d 100644 --- a/src/Main.java +++ b/src/Main.java @@ -2,8 +2,12 @@ public class Main { private static ISubscriber subscribers [] = { - new SimpleSubscriber(), - new ReallySimpleSubscriber(), + + new SphereArea(), new LucasSeries(), + new CircleArea() , new SphereCircumference () , + new Spherevolume(), new summationSeries() + , new Fibonacci() , new MultiplicationSeries (), new CircleVolum() + }; public static void main(String[] args) { Topic mathTopic = new Topic(); diff --git a/src/MultiplicationSeries.java b/src/MultiplicationSeries.java new file mode 100644 index 0000000..805d902 --- /dev/null +++ b/src/MultiplicationSeries.java @@ -0,0 +1,17 @@ +package com.company; + + +public class MultiplicationSeries implements ISubscriber +{ + @Override + public void notifySubscriber(String input){ + int n = Integer.parseInt(input); + + long r=1,i=1; + while(i<=n){ + r*=i; + i++; + } + System.out.println("the series Multiplication: "+r); + } +} diff --git a/src/ReallySimpleSubscriber.java b/src/ReallySimpleSubscriber.java deleted file mode 100644 index fb1114a..0000000 --- a/src/ReallySimpleSubscriber.java +++ /dev/null @@ -1,8 +0,0 @@ - -public class ReallySimpleSubscriber implements ISubscriber { - @Override - public void notifySubscriber(String input) { - // TODO Auto-generated method stub - System.out.println("Hello, I am really a simple subscriber and I am notified with " + input); - } -} diff --git a/src/SimpleSubscriber.java b/src/SimpleSubscriber.java deleted file mode 100644 index 5b0e4aa..0000000 --- a/src/SimpleSubscriber.java +++ /dev/null @@ -1,10 +0,0 @@ - -public class SimpleSubscriber implements ISubscriber { - - @Override - public void notifySubscriber(String input) { - // TODO Auto-generated method stub - System.out.println("Hello, I am a simple subscriber and I am notified with " + input); - } - -} diff --git a/src/SphereArea.java b/src/SphereArea.java new file mode 100644 index 0000000..b12d520 --- /dev/null +++ b/src/SphereArea.java @@ -0,0 +1,14 @@ +public class SphereArea implements ISubscriber { + static float pi = 3.14159f; + @Override + public void notifySubscriber(String input) { + + double Radius = Double.valueOf(input); + System.out.println( "Sphere Area = "+Calculate_Area(Radius)); + } + double Calculate_Area(double radius){ + return (4 * pi * radius * radius); + } +} + + diff --git a/src/SphereCircumference.java b/src/SphereCircumference.java new file mode 100644 index 0000000..22389f2 --- /dev/null +++ b/src/SphereCircumference.java @@ -0,0 +1,18 @@ +public class SphereCircumference implements ISubscriber{ + @Override + public void notifySubscriber(String input) + { + try + { + double radius = Double.parseDouble(input); + + double circumference = (2 * Math.PI * radius); + + System.out.println("Sphere Circumference = " + circumference); + } + catch (Exception e) + { + System.out.println("Exception: " + e); + } + } +} \ No newline at end of file diff --git a/src/spherevolume.java b/src/spherevolume.java new file mode 100644 index 0000000..99f7855 --- /dev/null +++ b/src/spherevolume.java @@ -0,0 +1,21 @@ +package com.company; +import java.lang.Math; + +public class Spherevolume implements ISubscriber{ + @Override + public void notifySubscriber(String input) + { + try + { + double radius = Double.valueOf(input); + + double Spherevolume = (4/3* Math.PI *Math.pow(radius,3)); + + System.out.println("Sphere volume : " + Spherevolume); + } + catch (Exception e) + { + System.out.println("Exception: " + e); + } + } +} diff --git a/src/summationSeries.java b/src/summationSeries.java new file mode 100644 index 0000000..ad39313 --- /dev/null +++ b/src/summationSeries.java @@ -0,0 +1,13 @@ +public class summationSeries implements ISubscriber{ + + public void notifySubscriber(String input) + { + double sum = 0; + double counter = Double.valueOf(input); + + for(double i=0 ; i<=counter ; i++){ //only for count number of series element + sum += i ; + } + System.out.println("series summation = " + sum ); + } +}