Friday, November 29, 2013

Longest Common Subseequence Problem Codings in java

import java.io.*;

public class LCS {


  public static void main(String [] args) throws IOException {

    System.out.println("LCS = "+lcsrec("BABCDAB","ABDACB"));
    System.out.println("LCS = "+lcsrec2("TATTACC","GTTCAATA"));
    System.out.println("LCS = "+lcsdyn("GTATATATATACC","GTTCCTAATA"));
  }


  // Precondition: Both x and y are non-empty strings.
  public static int lcsrec(String x, String y) {

    // If one of the strings has one character, search for that character
    // in the other string and return the appropriate answer.
    if (x.length() == 1)
      return find(x.charAt(0), y);
    if (y.length() == 1)
      return find(y.charAt(0), x);
     
    // Solve the problem recursively.

    // Corresponding beginning characters match.
    if (x.charAt(0) == y.charAt(0))
      return 1+lcsrec(x.substring(1), y.substring(1));

    // Corresponding characters do not match.
    else
      return max(lcsrec(x,y.substring(1)), lcsrec(x.substring(1),y));

  }

  // Note: This second recursive version, though more cumbersome in code
  //       because of how the substring method works more accurately
  //       mirrors the algorithms used in the dynamic programming method
  //       below, since this uses LCS's of prefixes to compute LCS's
  //       of longer strings.
  // Precondition: Both x and y are non-empty strings.
  public static int lcsrec2(String x, String y) {

    // If one of the strings has one character, search for that character
    // in the other string and return the appropriate answer.
    if (x.length() == 1)
      return find(x.charAt(0), y);
    if (y.length() == 1)
      return find(y.charAt(0), x);
     
    // Solve the problem recursively.

    // Corresponding last characters match.
    if (x.charAt(x.length()-1) == y.charAt(y.length()-1))
      return 1+lcsrec2(x.substring(0,x.length()-1),
               y.substring(0,y.length()-1));

    // Corresponding last characters do not match.
    else
      return max(lcsrec2(x,y.substring(0,y.length()-1)),
         lcsrec2(x.substring(0,x.length()-1),y));

  }

  // Precondition: Both x and y are non-empty strings.
  public static int lcsdyn(String x, String y) {

    int i,j;
    int lenx = x.length();
    int leny = y.length();
    int[][] table = new int[lenx+1][leny+1];

    // Initialize table that will store LCS's of all prefix strings.
    // This initialization is for all empty string cases.
    for (i=0; i<=lenx; i++)
      table[i][0] = 0;
    for (i=0; i<=leny; i++)
      table[0][i] = 0;
   
    // Fill in each LCS value in order from top row to bottom row,
    // moving left to right.
    for (i = 1; i<=lenx; i++) {
      for (j = 1; j<=leny; j++) {

        // If last characters of prefixes match, add one to former value.
        if (x.charAt(i-1) == y.charAt(j-1))
          table[i][j] = 1+table[i-1][j-1];

        // Otherwise, take the maximum of the two adjacent cases.
        else
          table[i][j] = max(table[i][j-1], table[i-1][j]);
      }
    }
    return table[lenx][leny];
  }

  // Returns 1 if c is contained in x, and 0 otherwise.
  public static int find(char c, String x) {
   
    for (int i=0; i<x.length(); i++)
      if (c == x.charAt(i))
        return 1;

    return 0;
  }

  // Returns the greater of x and y.
  public static int max(int x, int y) {
    if (x > y)
      return x;
    else
      return y;
  }
}

Java program for Throwing Dies in Randomized Counting

import java.util.Random;

public class Dice1 {

    public static void main(String[] args) {
        Random rand = new Random();
        int min = 1;
        int max = 6;
        int loop = 0;
        int diceRollOne = 0;
        int diceRollTwo = 0;
        int diceTotal = 0;
        int prevDiceTotal = 0;

        while (loop < 2) {
            loop++;
            diceRollOne = rand.nextInt(max - min + 1) + min;
            diceRollTwo = rand.nextInt(max - min + 1) + min;
            diceTotal = diceRollOne + diceRollTwo;

            System.out.println("Dice Roll 1: " + diceRollOne);
            System.out.println("Dice Roll 2: " + diceRollTwo);
            System.out.println("Dice Total: " + diceTotal);
            System.out.println("previous total: " + prevDiceTotal);

           

            if (diceRollOne == diceRollTwo || diceTotal == prevDiceTotal) {
                System.out.println("After " + loop + " loops the");
                System.out.println("Numbers Match, YOU WIN, GOOD DAY SIR!");
        System.exit(0);
                }
             else  
               {
                System.out.println("Numbers Match, YOU GET NOTHING, YOU LOSE, GOOD DAY SIR!");

}
prevDiceTotal = diceTotal;
}           

    }
}

Thursday, November 21, 2013

Random counding number programe in java

import java.util.Random;
public class QuickRandom {
    public static void main(String[] args) {
      System.out.println("The following is a list of 100 random" +
              " 3 digit numbers.");
      Random rand= new Random();
     
     
      for(int i=0;i<100;i++)
      {     
          int pick = rand.nextInt(900) + 100;
          System.out.println(pick);
         
          int sum = 0;
         
          sum += pick + pick;
         
          System.out.println("The sum is: " + sum + ".");
        }
  
    }
   
}
   
   

Defintion of Project scope

Project scope is the part of project planning that involves determining and documenting a list of specific project goals, deliverables, tasks, costs and deadlines.
The documentation of a project's scope, which is called a scope statement, terms of reference or statement of work, explains the boundaries of the project, establishes responsibilities for each team member and sets up procedures for how completed work will be verified and approved. During the project, this documentation helps the project team remain focused and on task. The scope statement also provides the project team with guidelines for making decisions about change requests during the project.
It is natural for parts of a large project to change along the way, so the better the project has been "scoped" at the beginning, the better the project team will be able to manage change. When documenting a project's scope, stakeholders should be as specific as possible in order to avoid scope creep, a situation in which one or more parts of a project ends up requiring more work, time or effort because of poor planning or miscommunication.
Effective scope management requires good communication to ensure that everyone on the team understands the scope of the project and agrees upon exactly how the project's goals will be met. As part of project scope management, the team leader should solicit approvals and sign-offs from the various stakeholders as the project proceeds, ensuring that the finished project, as proposed, meets everyone's needs.