Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.29 KB | None | 0 0
  1.     private class Node
  2.     {
  3.         public PrimeFactor pFactor;         // prime factor
  4.         public Node next;
  5.         public Node previous;
  6.         /**
  7.          * Default constructor for creating a dummy node.
  8.          */
  9.         public Node()
  10.         {
  11.        
  12.         }
  13.        
  14.         /**
  15.          * Precondition: p is a prime
  16.          *
  17.          * @param p  prime number
  18.          * @param m  multiplicity
  19.          * @throws IllegalArgumentException if m < 1
  20.          */
  21.         public Node(int p, int m) throws IllegalArgumentException
  22.         {  
  23.             if(m < 1) {
  24.                 throw new IllegalArgumentException();
  25.             }
  26.                 pFactor = new PrimeFactor(p,m);
  27.         }  
  28.        
  29.         /**
  30.          * Constructs a node over a provided PrimeFactor object.
  31.          *
  32.          * @param pf
  33.          * @throws IllegalArgumentException
  34.          */
  35.         public Node(PrimeFactor pf)  
  36.         {
  37.             pFactor = new PrimeFactor(pf.prime, pf.multiplicity);
  38.         }
  39.  
  40.         /**
  41.          * Printed out in the form: prime + "^" + multiplicity.  For instance "2^3".
  42.          * Also, deal with the case pFactor == null in which a string "dummy" is
  43.          * returned instead.  
  44.          */
  45.         @Override
  46.         public String toString()
  47.         {
  48.             String X = "";
  49.             if(pFactor == null) {
  50.                  X = "dummy";
  51.             }
  52.             else{
  53.                 if(pFactor.multiplicity == 1) {
  54.                 X = pFactor.prime + "";
  55.                 }
  56.                 else {
  57.                 X = pFactor.prime + "^" + pFactor.multiplicity;
  58.                 }
  59.             }
  60.             return X;
  61.         }
  62.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement