Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static int performEcholocation (final EcholocationManager manager) throws EcholocationException,LocatorConnectionException{
- int numberOfAttempts = 0;
- while(numberOfAttempts<=4){
- try{
- manager.connectLocator();
- break;
- }
- catch (LocatorConnectionException exception){
- numberOfAttempts+=1;
- if (numberOfAttempts>4){
- throw exception;
- }
- }
- }
- int[] scannerArray = new int[100];
- boolean isConnected = true;
- try{
- for (int i = 1;i<=100;++i){
- int depthValue = manager.locate(i);
- scannerArray[i-1] = depthValue;
- }
- }
- catch(EcholocationException exception1){
- isConnected = false;
- try{
- manager.disconnectLocator();
- }
- catch(LocatorConnectionException ignored){
- }
- throw exception1;
- }
- finally{
- if (isConnected){
- try{
- manager.disconnectLocator();
- }
- catch(LocatorConnectionException ignored){
- }
- }
- }
- int result = 0;
- for (int i : scannerArray){
- if (result==0){
- result = i;
- }
- else{
- result^=i;
- }
- }
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement