Wednesday, June 3, 2015

DISTRIBUTED OPERATING SYSTEMS

AIM:

To write a java program for RMI lottery application in distributed operating systems.

ALGORITHM:

Step 1:        Start the program.

Step 2:        Consider a distributed system that consists of two processes which   
                            communicate with each other.

Step 3:        Let P be a state predicate on the local state of one process and Q be a state
                           predicate on the local state of the other process. Assume that neither P nor Q        
                           are stable (i.e. closed)

Step 4:        Design a superimposed computation which detects that there exists an  
  interleaving of underlying events in this system where at some state P ^Q    
  holds.

Step 5:        Design a RMI Lottery application

Step 6:        Each time you run the client program -- “java LotteryClient n”, the server  
                           program “LotteryServer” will generate n set of Lottery numbers

Step 7:        Here n is a positive integer, representing the money you will spend on Lottery  
  in sterling pounds

Step 8:        Events in a superposed computation may occur in at the same instant as the  
  Underlying events and/or at different instants

Step 9:        End of program


 PROGRAM:

import java.util.Random;
import java.util.Scanner;

 class Lottery
{
      private int g1;
      private int g2;
      private int g3;
      private int num1;
      private int num2;
      private int num3;
      private int match1;
      private int match2;
      private int match3;
      private int order1;
      private int order2;
      private int order3;
      private int totalMatch;
      private int match;

          public Lottery()
          {   
              
                  Scanner inputDevice = new Scanner(System.in);
                  Random random = new Random();
                  num1 = random.nextInt(10);
                  num2 = random.nextInt(10);
                  num3 = random.nextInt(10);
                     //System.out.println("Random number = " + number);
                  System.out.println(" Enter a number  between 0 - 9");
                  g1 = inputDevice.nextInt();
                  System.out.println("Enter another number between 0-9");
                  g2 = inputDevice.nextInt();
                  System.out.println("Enter another number between 0-9");
                  g3 = inputDevice.nextInt();
                     //System.out.println("Your guess was " + guess);
          }
         

                public void checkGuesses()
             {
                if (g1 == num1)
                        {
                         match1 = 1;
                        }
                else if(g1 == num2)
                    {
                          match1 = 2;
                        }
                else if(g1 == num3)
                        {
                          match1 = 3;
                        }
               
               
                if (g2 == num1)
                   {
                         match2 =1 ;
                   }
                    else if (g2 == num2)
                        {
                         match2 =2 ;
                        }
                    else if (g2 == num3)
                        {
                          match2 = 3 ;
                        }
               if (g3 == num1)
                            {
                             match3 = 1;
                            }
                         else if (g3 == num2)
                                    {
                                     match3 = 2;
                                    }
                         else if (g3 == num3)
                                    {
                                      match3 = 3 ;
                                    }
            
                           
           
            if(match1 > 0 || match2 > 0 || match3 >0)
            {
                if(match1 == match2 || match1 == match3)
                {
                        totalMatch = 1;
                }
            else if (match1 > 0 && match2 > 0 && match3 > 0)
                {
                        totalMatch = 2;
                }
            else if (match1 > 0 && match2 > 0 && match3 > 0)
                    {
                        totalMatch = 3;     
                    }
                else
               {
                        totalMatch = 1;
                   }
            }
           }
                public void checkExact()
             {
                        
                 if (g1== num1 && g2 == num2 && g3 == num3)
                 {
                        System.out.println("You have won the jackpot of $1,000,000");
                 }
             }

                public void checkOrder()
             {
                
                 if (order1 == order2)
                 {
                         match -- ;
                 }
                 if (order2 == order3)
                 {
                         match -- ;
                 }
                 if ( order1 == order3)
                 {
                         match -- ;
                 }
}
       
                public void showdata()
                {
                        System.out.println("The original number was; " + num1 +
                                         num2 + num3);
                        System.out.println("Your guess was: " + g1 + g2 + g3);
                        System.out.println("You have made a match: " + totalMatch);

                       //System.out.println("You hit the JackPot and won One Million Dollars" );
                }           
            
}
public class LotteryTest      //this line declares the class Lottery test
{
             public static void main(String[] args)
        {
           Lottery guess1 = new Lottery();
           guess1.checkGuesses();
           //guess1.checkOrder();
           //guess1.checkExact();
           guess1.showdata();
  
        }
}
               





















No comments:

Post a Comment