diff --git a/init.txt b/init.txt new file mode 100644 index 0000000..87fae37 --- /dev/null +++ b/init.txt @@ -0,0 +1,2 @@ +init repo + diff --git a/src/CircleAreaObserver.java b/src/CircleAreaObserver.java new file mode 100644 index 0000000..6fa47fd --- /dev/null +++ b/src/CircleAreaObserver.java @@ -0,0 +1,10 @@ +public class CircleAreaObserver implements ISubscriber { + @Override + public void notifySubscriber(String input) { + System.out.println("Circle of radius = " + " has Area = " + areaOfCircle(Integer.parseInt(input))); + } + private double areaOfCircle(int r){ + return Math.PI *r *2; + + } +} diff --git a/src/CircleCircumference.java b/src/CircleCircumference.java new file mode 100644 index 0000000..0c96a85 --- /dev/null +++ b/src/CircleCircumference.java @@ -0,0 +1,8 @@ +public class CircleCircumference implements ISubscriber { + + public void notifySubscriber(String input) { + double radius=Double.parseDouble(input); + double circumference= Math.PI * 2*radius; + System.out.println( "The circumference of this circle is: "+circumference) ; + } +} \ No newline at end of file diff --git a/src/CircleVolume.java b/src/CircleVolume.java new file mode 100644 index 0000000..dfabeff --- /dev/null +++ b/src/CircleVolume.java @@ -0,0 +1,12 @@ +import java.util.Scanner; +import java.lang.Math; + +public class CircleVolume implements ISubscriber { + + public void notifySubscriber(String input) { + final double PI = 3.1415926535; + double radius = Double.parseDouble(input); + double result = ((4.0/3.0)*PI*Math.pow(radius,3)); + System.out.println( "Circle Volume = "+result) ; + } +} diff --git a/src/LucasSeriesSub.java b/src/LucasSeriesSub.java new file mode 100644 index 0000000..0280c3f --- /dev/null +++ b/src/LucasSeriesSub.java @@ -0,0 +1,39 @@ +import java.util.ArrayList; + +public class LucasSeriesSub implements ISubscriber { + @Override + public void notifySubscriber(String input) { + int numOfTerms = Integer.parseInt(input); + ArrayListlucesResult = new ArrayList(); + int temp1 = 2 , temp2 = 1; + int j = 0 , temp = 0; + if(numOfTerms == 1) + { + lucesResult.add(temp1); + } + else if (numOfTerms == 2) + { + lucesResult.add(temp1); + lucesResult.add(temp2); + } + else if (numOfTerms > 2) + { + lucesResult.add(temp1); + lucesResult.add(temp2); + for(int i = 2 ; i < numOfTerms ; i++) + { + temp1 = lucesResult.get(j); + temp2 = lucesResult.get(++j); + temp = temp1 + temp2; + lucesResult.add(temp); + } + } + else + { + System.out.println("Not invalid Input"); + System.exit(0); + } + System.out.println("The Series is : " + lucesResult); + } + +} diff --git a/src/Main.java b/src/Main.java index 9b8c2b0..842d719 100644 --- a/src/Main.java +++ b/src/Main.java @@ -2,8 +2,15 @@ public class Main { private static ISubscriber subscribers [] = { - new SimpleSubscriber(), - new ReallySimpleSubscriber(), + new CircleCircumference(), + new CircleVolume(), + new MultiplicationSeries(), + new CircleAreaObserver(), + new Power(), + new SphereVolume(), + new SphereAreaSub(), + new summtionSeries(), + new LucasSeriesSub() }; 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..79c5dc4 --- /dev/null +++ b/src/MultiplicationSeries.java @@ -0,0 +1,17 @@ +public class MultiplicationSeries implements ISubscriber { + public void notifySubscriber(String input){ + // TODO Auto-generated method stub + + int n =Integer.parseInt(input); + int result = n; + + + while(n>1) { + n-=1; + result =result *n; + + + } + System.out.println("the multiplication series of " + input +" is " + result ); + } +} diff --git a/src/Power.java b/src/Power.java new file mode 100644 index 0000000..0fb2488 --- /dev/null +++ b/src/Power.java @@ -0,0 +1,8 @@ +import java.math.*; +public class Power implements ISubscriber { + @Override + public void notifySubscriber(String input) { + // TODO Auto-generated method stub + System.out.println("2 Power "+input+": "+Math.pow(2, Double.parseDouble(input))); + } +} 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/SphereAreaSub.java b/src/SphereAreaSub.java new file mode 100644 index 0000000..ae5818d --- /dev/null +++ b/src/SphereAreaSub.java @@ -0,0 +1,13 @@ + +public class SphereAreaSub implements ISubscriber{ + + + public void notifySubscriber(String input) { // input will be a single integer for all functions. + int r = Integer.parseInt(input);// radius + double area; + area = 4 * 3.14 * (r*r); // 4Pi*r^2. + System.out.println("Sphere Area with r = "+ r +": " + area); + } + + +} diff --git a/src/SphereVolume.java b/src/SphereVolume.java new file mode 100644 index 0000000..9651a8b --- /dev/null +++ b/src/SphereVolume.java @@ -0,0 +1,11 @@ + +public class SphereVolume implements ISubscriber{ + public void notifySubscriber(String input) { + Float Rad; + double Res; + Rad = Float.parseFloat(input); + Res=(4/3)*(3.14)*(Rad*Rad*Rad); + System.out.println("Sphere Volume =" + Res); + } + +} diff --git a/src/summtionSeries.java b/src/summtionSeries.java new file mode 100644 index 0000000..6886201 --- /dev/null +++ b/src/summtionSeries.java @@ -0,0 +1,12 @@ +public class summtionSeries implements ISubscriber { + public void notifySubscriber(String input){ + int x = Integer.parseInt(input); + int sum = 0; + for (int i = 0; i <= x; i++) { + sum += i; + } + System.out.println(sum); + //20160152 ali osama ali + + } +}