diff --git a/src/CircleArea.java b/src/CircleArea.java new file mode 100644 index 0000000..ce21b6a --- /dev/null +++ b/src/CircleArea.java @@ -0,0 +1,17 @@ + +public class CircleArea implements ISubscriber{ + + @Override + public void notifySubscriber(String input) { + double reduis=Double.parseDouble(input); + System.out.println("Area= "+area(reduis)); + + } + + + public double area(double reduis) { + double setArea=Math.PI * reduis *reduis; + return setArea; + } +} + diff --git a/src/SphereArea.java b/src/SphereArea.java new file mode 100644 index 0000000..e856d8d --- /dev/null +++ b/src/SphereArea.java @@ -0,0 +1,25 @@ +import java.sql.SQLOutput; + +public class SphereArea implements ISubscriber { + + + @Override + public void notifySubscriber(String input) { + + double R = Double.parseDouble(input); + + double sphereArea = calcSphereArea(R); + + System.out.println("The Sphere Area = " + sphereArea); + + } + + double calcSphereArea(double r){ + + double sphereArea = 0.0; + + sphereArea = 4 * Math.PI * Math.pow(r, 2); + + return sphereArea; + } +} diff --git a/src/SphereCircumference.java b/src/SphereCircumference.java new file mode 100644 index 0000000..dac652c --- /dev/null +++ b/src/SphereCircumference.java @@ -0,0 +1,24 @@ +public class SphereCircumference implements ISubscriber{ + private double getSphereCircumference(double r) { + double area=2*Math.PI*r; + return area; + } + @Override + public void notifySubscriber(String input) { + double r; + try { + r=Double.parseDouble(input); + } catch (Exception e) { + System.out.println("enter a real number"); + return; + } + + if(r<0) { + System.out.println("r must be >= 0"); + return; + } + System.out.println("Area= "+getSphereCircumference(r)); + + } + +} diff --git a/src/Sphere_Volume.java b/src/Sphere_Volume.java new file mode 100644 index 0000000..50315f6 --- /dev/null +++ b/src/Sphere_Volume.java @@ -0,0 +1,17 @@ + +public class Sphere_Volume implements ISubscriber { + @Override + public void notifySubscriber(String input) { + + double Radius = Double.parseDouble(input); + if(Radius < 0) + { + System.out.println("Radius can not be equal nagative number"); + } + else { + double Volume = (4/3) * Math.PI * Math.pow(Radius, 3); + System.out.println("Volume = "+ Volume); + } + + } +} diff --git a/src/SummationSeries.java b/src/SummationSeries.java new file mode 100644 index 0000000..3c84dc1 --- /dev/null +++ b/src/SummationSeries.java @@ -0,0 +1,15 @@ +public class SummationSeries implements ISubscriber +{ + @Override + public void notifySubscriber(String input) + { + int end = Integer.parseInt(input); + int sum = sigma(end); + System.out.println("The sum from 1 to the end number = " + sum); + } + + public static int sigma(int end) + { + return (end*(end+1))/2; + } +} diff --git a/src/fibonacci.java b/src/fibonacci.java new file mode 100644 index 0000000..ce2f362 --- /dev/null +++ b/src/fibonacci.java @@ -0,0 +1,22 @@ +public class fibonacci implements ISubscriber { + + int calcFib(String input){ + int x = Integer.parseInt(input); + int ans = 0 ; + int fibN_1 = 1 ,fibN_2 = 1 ,fibN = 0; + + for(int i = 2 ; i < x ; i ++) { + fibN = fibN_1 + fibN_2; + fibN_2 = fibN_1; + fibN_1 = fibN; + } + return fibN; + } + @Override + public void notifySubscriber(String input) { + // TODO Auto-generated method stub + + System.out.println("fibonacci of "+input+ " is " + calcFib(input)); + + } +} \ No newline at end of file