@@ -0,0 +1,2611 @@
+import java.math.BigDecimal;%0Aimport com.mongodb.BasicDBObject;%0Aimport com.mongodb.DB;%0Aimport com.mongodb.DBCollection;%0Aimport com.mongodb.Mongo;%0Aimport com.mongodb.DBCursor;%0Aimport com.mongodb.MongoException;%0A%0A%0A/*Class: SingleCalculatedSum%0A * brief: Calculated the sum of all salaries in single thread mode.%0A * */%0Apublic class  SingleCalculatedSum%7B  %0A    static public BigDecimal sum() %7B  %0A    /*%0A     * Define the number of employees%0A     * */%0A        int count=1000000;%0A        BigDecimal s = BigDecimal.ZERO;  %0A        BigDecimal cSalary = BigDecimal.ZERO;%0A        BigDecimal parameter = new BigDecimal(1);%0A        int monthySalary=0;%0A        double incrementalRate=0;%0A        %0A          %09      try %7B%0A          %09    %09/*%0A          %09    %09 * Connecting to the db%0A          %09    %09 * */%0A          %09        Mongo mg = new Mongo(%22localhost%22,27017);%0A      %09%09%09    DB db = mg.getDB(%22sap%22);%0A      %09%09        DBCollection employees = db.getCollection(%22Data%22);  %0A      %09%09        BasicDBObject query = new BasicDBObject();%0A      %09%09        BasicDBObject field = new BasicDBObject();%0A      %09%09        %0A      %09%09        for (int i = 0; i %3C count; i++) %7B  %0A                 %09%09%09  query.put(%22ID%22,String.valueOf(i));%0A                 %09%09     field.put(%22MonthySalary%22, 1);%0A                 %09%09     field.put(%22IncrementalRate%22, 1);%0A                 %09%09     DBCursor cursor = employees.find(query,field);%0A%0A                 %09%09     while (cursor.hasNext()) %7B%0A                 %09%09    %09BasicDBObject obj = (BasicDBObject) cursor.next();  %0A                 %09%09%09%09monthySalary =%09 obj.getInt(%22MonthySalary%22);%0A                 %09%09%09%09incrementalRate= obj.getDouble(%22IncrementalRate%22) ;%0A                                BigDecimal mSalary = new BigDecimal(monthySalary);%0A                                BigDecimal iRate = new BigDecimal(incrementalRate);%0A                                cSalary =  iRate.add(parameter);%0A                                cSalary = cSalary.multiply(mSalary);          %0A                 %09%09     %7D%09 %0A                 %09%09    s = s.add(cSalary);%0A                    %7D  %7D  catch (MongoException e) %7B%0A             %09%09%09e.printStackTrace();%0A                    %7D%0A            %0A        return s;  %0A%7D%0A    %0A  %0A    public static void main(String%5B%5D args) %7B  %0A        long start = System.currentTimeMillis();   %0A        double sumLast; %0A        BigDecimal sum2 = sum();%0A        sumLast= sum2.doubleValue(); %0A        long end = System.currentTimeMillis();  %0A        long runningTime = end - start;      %0A        System.out.println( %22The total salary of all employees this month is: %22+sumLast+%22 RunningTime:%22 + runningTime);  %0A    %7D  %0A  %0A%7D  %0A %0A

Create SingleCalculatedSum.java