Advertisement
anas_harby

Untitled

May 2nd, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.14 KB | None | 0 0
  1. public static void main(String[] args) throws IOException {
  2.         System.out.println("Enter number of variables:");
  3.         numberOfBits = in.nextInt();       
  4.        
  5.         System.out.println("Enter minterms in decimal <-1 to finish>:");
  6.         while (true) {
  7.             int input;
  8.             input = in.nextInt();
  9.             if (input == -1)
  10.                 break;
  11.             minterms.add(input);
  12.         }
  13.         System.out.println("Enter don'tcares in decimal <-1 to finish>:");
  14.         while (true) {
  15.             int input;
  16.             input = in.nextInt();
  17.             if (input == -1)
  18.                 break;
  19.             dontcares.add(input);
  20.         }
  21.         }
  22.         fillArrayList();
  23.         decimalToBinary();
  24.         doComparisons();
  25.        
  26.         System.out.println("________________________________________________________________" + "\n");
  27.         System.out.println("Grouping:");
  28.         System.out.println();
  29.         for (int k = 0; k < comparisons.size(); k++) {
  30.             boolean comparisonHasElements = false;
  31.  
  32.             for (int i = 0; i < comparisons.get(k).size(); i++) {
  33.                 if (comparisons.get(k).get(i).isEmpty())
  34.                     continue;
  35.                 for (int j = 0; j < comparisons.get(k).get(i).size(); j++) {
  36.                     String binaryRepresentation = comparisons.get(k).get(i).get(j).split(" ", 2)[0];
  37.                     String numericRepresentation = comparisons.get(k).get(i).get(j).split(" ", 2)[1];
  38.                     System.out.println(binaryRepresentation + "\t" + "(" + numericRepresentation + ")");
  39.                 }
  40.                 comparisonHasElements = true;
  41.                 System.out.println("-----------------");
  42.             }
  43.             if (comparisonHasElements) {
  44.                 System.out.println("_________________" + "\n");
  45.             }
  46.         }
  47.         if (minterms.isEmpty()==true)
  48.         {
  49.             System.out.println("Expression = 0");
  50.             System.exit(0);
  51.         }
  52.        
  53.         System.out.println("Prime Implicants:" + "\n");
  54.         for (int i = 0; i < primeImplicants.size(); i++) {
  55.             String binaryRepresentation = primeImplicants.get(i).split(" ", 2)[0];
  56.             String numericRepresentation =  primeImplicants.get(i).split(" ", 2)[1];
  57.             System.out.println(binaryRepresentation + "\t" + "(" + numericRepresentation + ")");
  58.         }
  59.         System.out.println("\n" + "Expression:");
  60.         System.out.println(findExpression(primeImplicants));
  61.         System.out.println("_________________" + "\n");
  62.         System.out.println("Coverage Table:");
  63.         System.out.println();
  64.         printCoverageTable();
  65.         System.out.println("_________________" + "\n" + "\n" + "Essential Prime Implicants:" + "\n");
  66.         countAppearances();
  67.         if (containsOne()) {
  68.             getReducedEssentialImplicants();
  69.             if (!needsCombinations()) {
  70.                 for (int i = 1; i <= primeImplicants.size() && !foundCombination; i++)
  71.                     generateCombinations(1, 0, i);
  72.             }
  73.             else {
  74.                 for(int i=0; i<essentialPrimeImplicantsContainingOne.size(); i++) {
  75.                     String binaryRepresentation = essentialPrimeImplicantsContainingOne.get(i).split(" ",2)[0];
  76.                     String numericRepresentation = essentialPrimeImplicantsContainingOne.get(i).split(" ",2)[0];
  77.                     System.out.println(binaryRepresentation + "\t" + "(" + numericRepresentation + ")");
  78.                 }
  79.                 System.out.println("\n" + "Expression:");
  80.                 System.out.println(findExpression(essentialPrimeImplicantsContainingOne));
  81.                
  82.             }
  83.         }
  84.         else {
  85.             for (int i = 1; i <= primeImplicants.size() && !foundCombination; i++)
  86.                 generateCombinations(1, 0, i);
  87.         }
  88.  
  89.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement