From 327eef3e7fb6c3b34b8314b4e083c30a55cf9362 Mon Sep 17 00:00:00 2001 From: sarubi Date: Fri, 27 Jan 2017 15:50:05 +0530 Subject: [PATCH 1/2] implementation of getMoment --- src/main/java/com/performancemodels/App.java | 9 +++++- .../DistributionUtilities.java | 31 ++++++++++++++++--- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/performancemodels/App.java b/src/main/java/com/performancemodels/App.java index fc472ba..a8e3344 100644 --- a/src/main/java/com/performancemodels/App.java +++ b/src/main/java/com/performancemodels/App.java @@ -8,6 +8,13 @@ public class App { public static void main( String[] args ) { - System.out.println( "Hello World!" ); + String input= args[0]; + String i= args[1]; + int y= Integer.parseInt(i); + //int moment = Integer.parseInt(args[1]); + System.out.println("Start to calculate the moment"); + double ex_moment= DistributionUtilities.getMoment(y,input); + System.out.println("The moment("+2+ ") = " + ex_moment); + System.out.println("exiting from the program"); } } diff --git a/src/main/java/com/performancemodels/DistributionUtilities.java b/src/main/java/com/performancemodels/DistributionUtilities.java index 1d8aa13..aa91fb0 100644 --- a/src/main/java/com/performancemodels/DistributionUtilities.java +++ b/src/main/java/com/performancemodels/DistributionUtilities.java @@ -1,16 +1,37 @@ package com.performancemodels; +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; + /** * Created by temp on 1/26/17. */ public class DistributionUtilities { - public static double getMoment(int i, String FileName){ - - return 0.0; + public static double getMoment(int i, String FileName) { + String sCurrentLine = null; + BufferedReader reader = null; + double sigmaX = 0,moment_result; + double x,n=0; + // lets fire up a buffered reader and skip right to that spot. + try { + reader = new BufferedReader(new FileReader(FileName)); + while ((sCurrentLine = reader.readLine()) != null) { + n++; + x = Double.parseDouble(sCurrentLine); + sigmaX += Math.pow(x, i); + } + reader.close(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + moment_result = (sigmaX / n); + return moment_result; } - - } From cd3c26ecd70a05373c18e777208843b1a04830c8 Mon Sep 17 00:00:00 2001 From: Sarubi Thillainathan Date: Fri, 27 Jan 2017 15:52:35 +0530 Subject: [PATCH 2/2] Update App.java --- src/main/java/com/performancemodels/App.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/performancemodels/App.java b/src/main/java/com/performancemodels/App.java index a8e3344..c74b54e 100644 --- a/src/main/java/com/performancemodels/App.java +++ b/src/main/java/com/performancemodels/App.java @@ -9,12 +9,10 @@ public class App public static void main( String[] args ) { String input= args[0]; - String i= args[1]; - int y= Integer.parseInt(i); - //int moment = Integer.parseInt(args[1]); + int moment = Integer.parseInt(args[1]); System.out.println("Start to calculate the moment"); double ex_moment= DistributionUtilities.getMoment(y,input); - System.out.println("The moment("+2+ ") = " + ex_moment); + System.out.println("The moment("+args[1]+ ") = " + ex_moment); System.out.println("exiting from the program"); } }