Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2014
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.21 KB | None | 0 0
  1. import javax.ejb.*;
  2. import javax.naming.*;
  3.  
  4. /**
  5.  * Aplikacja do zadania 05
  6.  * @author Krzysztof "Szalix" Szala
  7.  */
  8. public class Client {
  9.     public static void main(String[] args) throws Exception {
  10.         //Wyszukiwanie implementacji interfejsu
  11.         Context initialContext = new InitialContext();
  12.         HMonitor monitor = (HMonitor) initialContext.lookup("java:global/ejb-project/HMonitorImpl");
  13.        
  14.         //zmienne pomocnicze do algorytmu
  15.         double result = 0;
  16.         double currentValue = 0;
  17.         double squareSum = 0;
  18.         double sumToMean = 0;
  19.         double mean =0;
  20.         int numberOfElements = 0;
  21.        
  22.         //sprawdzenie czy uda sie zarejestrowac
  23.         if(hMonitor.register(5, "94067") == true){
  24.             //wczytanie kazdego elementu z iteratora do listy
  25.             //policzenie wartosci pomocniczych
  26.             while(monitor.hasNext()){
  27.                 currentValue = monitor.next();
  28.                 sumToMean += currentValue;
  29.                 squareSum += currentValue*currentValue;
  30.                 numberOfElements++;
  31.             }
  32.             //srednia
  33.             mean = sumToMean / numberOfElements;
  34.             //wynik srednia kwadratow przez ilosc elementow i srednia kwadrat
  35.             result = squareSum/numberOfElements - mean*mean;
  36.             System.out.print(result);
  37.         }
  38.         else{
  39.             System.out.println("Error while registration!");
  40.         }
  41.        
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement