Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.64 KB | None | 0 0
  1. public class BenfordsLaw{
  2.     public static int calculateLeadingDigit(int number) {
  3.         int absoluteNumber = Math.abs(number);
  4.         while(absoluteNumber >= 10);
  5.         {
  6.             absoluteNumber=(absoluteNumber / 10);
  7.         }
  8.         return absoluteNumber; //represents leading digit
  9.     }
  10.     public static double[] generateBenfordNumbers(double initialAmount, double growthRate, int numberPeriods) {
  11.         for(i=0;i=numberPeriods;i++){
  12.             double growthNumber = (initialAmount * (1+growthRate)); //generate each of the growth numbers
  13.         }
  14.         return growthNumber;
  15.     }
  16.     public static double[] calculateLeadingDigitProportions(double[] numbers) {
  17.         int arraySize = numbers.length; //number of values in the array
  18.        
  19.         int countZero = 0;
  20.         int countOne = 0;
  21.         int countTwo = 0;
  22.         int countThree = 0;
  23.         int countFour = 0;
  24.         int countFive = 0;
  25.         int countSix = 0;
  26.         int countSeven = 0;
  27.         int countEight = 0;
  28.         int countNine = 0;
  29.         for(i=0;i < arraySize; i++){
  30.             int leadingDigit = calculateLeadingDigit((int)numbers[i]);
  31.             if(leadingDigit == 0) {
  32.                 countZero++;
  33.             }
  34.             if(leadingDigit == 1) {
  35.                 countOne++;
  36.             }
  37.             if(leadingDigit == 2) {
  38.                 countTwo++;
  39.             }
  40.             if(leadingDigit == 3) {
  41.                 countThree++;
  42.             }
  43.             if(leadingDigit == 4) {
  44.                 countFour++;
  45.             }
  46.             if(leadingDigit == 5) {
  47.                 countFive++;
  48.             }
  49.             if(leadingDigit == 6) {
  50.                 countSix++;
  51.             }
  52.             if(leadingDigit == 7) {
  53.                 countSeven++;
  54.             }
  55.             if(leadingDigit == 8) {
  56.                 countEight++;
  57.             }
  58.             if(leadingDigit == 9) {
  59.                 countNine++;
  60.             }          
  61.         }
  62.         double[] array = {(countZero/arraySize),(countOne/arraySize),(countTwo/arraySize),(countThree/arraySize),(countFour/arraySize),(countFive/arraySize),(countSix/arraySize),(countSeven/arraySize),(countEight/arraySize),(countNine/arraySize)};
  63.         return array;
  64.     }
  65.     public static double calculateDistance(double[] a, double[] b) {
  66.         int sizeArray = a.length;
  67.         double total = 0;
  68.         for(i=0; i < sizeArray; i++) {
  69.             total = total + Math.pow((a[i]-b[i]),2);
  70.         }
  71.         double distanceEuclidian = Math.sqrt(total);
  72.         return distanceEuclidian;
  73.     }
  74.     public static void main(String[]args){
  75.         double initialAmount = 100;
  76.         System.out.println("The starting amount is"+initialAmount);
  77.         double numberSteps = 1000;
  78.         System.out.println("The number of periods is"+numberSteps);
  79.         double rateGrowth = 0.01;
  80.         System.out.println("The growth rate is"+rateGrowth);
  81.         double[] benfordSequence = generateBenfordNumbers(initialAmount, rateGrowth, numberSteps);
  82.         double[] randomNumbers = BenfordSupportCode.generateRandomNumbers(1000);
  83.         //generate array of 1000 numbers
  84.         double[] distributionBenford = calculateLeadingDigitProportions(benfordSequence);
  85.         double[] distributionRandom = calculateLeadingDigitProportions(randomNumbers);
  86.         //step 3 of question 6, calling method to calculate distribution
  87.         for(i=0;i<10;i++){
  88.             System.out.println("For Benford, the distribution of leading digit" + i + "is" + distributionBenford[i]);
  89.         }
  90.         for(i=0;i<10;i++){
  91.             System.out.println("For random generation, the distribution of leading digit" + i + "is" + distributionRandom[i]);
  92.         }
  93.         double distributionIdeal = BenfordSupportCode.getBenfordProbabilities();
  94.         double distanceBenford = calculateDistance(distributionBenford, distributionIdeal);
  95.         System.out.println("The distance of the exponential growth group is " + distanceBenford);
  96.         double distanceRandom = calculateDistance(distributionRandom, distributionIdea);
  97.         System.out.println("The distance of the exponential growth group is " + distanceRandom);
  98.     }
  99. }      
  100.  
  101.  
  102. BenfordsLaw.java:11: error: cannot find symbol
  103.                 for(i=0;i=numberPeriods;i++){
  104.                     ^
  105.   symbol:   variable i
  106.   location: class BenfordsLaw
  107. BenfordsLaw.java:11: error: cannot find symbol
  108.                 for(i=0;i=numberPeriods;i++){
  109.                         ^
  110.   symbol:   variable i
  111.   location: class BenfordsLaw
  112. BenfordsLaw.java:11: error: cannot find symbol
  113.                 for(i=0;i=numberPeriods;i++){
  114.                                         ^
  115.   symbol:   variable i
  116.   location: class BenfordsLaw
  117. BenfordsLaw.java:14: error: cannot find symbol
  118.                 return growthNumber;
  119.                        ^
  120.   symbol:   variable growthNumber
  121.   location: class BenfordsLaw
  122. BenfordsLaw.java:29: error: cannot find symbol
  123.                 for(i=0;i < arraySize; i++){
  124.                     ^
  125.   symbol:   variable i
  126.   location: class BenfordsLaw
  127. BenfordsLaw.java:29: error: cannot find symbol
  128.                 for(i=0;i < arraySize; i++){
  129.                         ^
  130.   symbol:   variable i
  131.   location: class BenfordsLaw
  132. BenfordsLaw.java:29: error: cannot find symbol
  133.                 for(i=0;i < arraySize; i++){
  134.                                        ^
  135.   symbol:   variable i
  136.   location: class BenfordsLaw
  137. BenfordsLaw.java:30: error: cannot find symbol
  138.                         int leadingDigit = calculateLeadingDigit((int)numbers[i]
  139. );
  140.                                                                               ^
  141.   symbol:   variable i
  142.   location: class BenfordsLaw
  143. BenfordsLaw.java:68: error: cannot find symbol
  144.                 for(i=0; i < sizeArray; i++) {
  145.                     ^
  146.   symbol:   variable i
  147.   location: class BenfordsLaw
  148. BenfordsLaw.java:68: error: cannot find symbol
  149.                 for(i=0; i < sizeArray; i++) {
  150.                          ^
  151.   symbol:   variable i
  152.   location: class BenfordsLaw
  153. BenfordsLaw.java:68: error: cannot find symbol
  154.                 for(i=0; i < sizeArray; i++) {
  155.                                         ^
  156.   symbol:   variable i
  157.   location: class BenfordsLaw
  158. BenfordsLaw.java:69: error: cannot find symbol
  159.                         total = total + Math.pow((a[i]-b[i]),2);
  160.                                                     ^
  161.   symbol:   variable i
  162.   location: class BenfordsLaw
  163. BenfordsLaw.java:69: error: cannot find symbol
  164.                         total = total + Math.pow((a[i]-b[i]),2);
  165.                                                          ^
  166.   symbol:   variable i
  167.   location: class BenfordsLaw
  168. BenfordsLaw.java:81: error: method generateBenfordNumbers in class BenfordsLaw c
  169. annot be applied to given types;
  170.                 double[] benfordSequence = generateBenfordNumbers(initialAmount,
  171.  rateGrowth, numberSteps);
  172.                                            ^
  173.   required: double,double,int
  174.   found: double,double,double
  175.   reason: actual argument double cannot be converted to int by method invocation
  176.  conversion
  177. BenfordsLaw.java:82: error: cannot find symbol
  178.                 double[] randomNumbers = BenfordSupportCode.generateRandomNumber
  179. s(1000);
  180.                                          ^
  181.   symbol:   variable BenfordSupportCode
  182.   location: class BenfordsLaw
  183. BenfordsLaw.java:87: error: cannot find symbol
  184.                 for(i=0;i<10;i++){
  185.                     ^
  186.   symbol:   variable i
  187.   location: class BenfordsLaw
  188. BenfordsLaw.java:87: error: cannot find symbol
  189.                 for(i=0;i<10;i++){
  190.                         ^
  191.   symbol:   variable i
  192.   location: class BenfordsLaw
  193. BenfordsLaw.java:87: error: cannot find symbol
  194.                 for(i=0;i<10;i++){
  195.                              ^
  196.   symbol:   variable i
  197.   location: class BenfordsLaw
  198. BenfordsLaw.java:88: error: cannot find symbol
  199.                         System.out.println("For Benford, the distribution of lea
  200. ding digit" + i + "is" + distributionBenford[i]);
  201.  
  202.               ^
  203.   symbol:   variable i
  204.   location: class BenfordsLaw
  205. BenfordsLaw.java:88: error: cannot find symbol
  206.                         System.out.println("For Benford, the distribution of lea
  207. ding digit" + i + "is" + distributionBenford[i]);
  208.  
  209.                                              ^
  210.   symbol:   variable i
  211.   location: class BenfordsLaw
  212. BenfordsLaw.java:90: error: cannot find symbol
  213.                 for(i=0;i<10;i++){
  214.                     ^
  215.   symbol:   variable i
  216.   location: class BenfordsLaw
  217. BenfordsLaw.java:90: error: cannot find symbol
  218.                 for(i=0;i<10;i++){
  219.                         ^
  220.   symbol:   variable i
  221.   location: class BenfordsLaw
  222. BenfordsLaw.java:90: error: cannot find symbol
  223.                 for(i=0;i<10;i++){
  224.                              ^
  225.   symbol:   variable i
  226.   location: class BenfordsLaw
  227. BenfordsLaw.java:91: error: cannot find symbol
  228.                         System.out.println("For random generation, the distribut
  229. ion of leading digit" + i + "is" + distributionRandom[i]);
  230.  
  231.                         ^
  232.   symbol:   variable i
  233.   location: class BenfordsLaw
  234. BenfordsLaw.java:91: error: cannot find symbol
  235.                         System.out.println("For random generation, the distribut
  236. ion of leading digit" + i + "is" + distributionRandom[i]);
  237.  
  238.                                                       ^
  239.   symbol:   variable i
  240.   location: class BenfordsLaw
  241. BenfordsLaw.java:93: error: cannot find symbol
  242.                 double distributionIdeal = BenfordSupportCode.getBenfordProbabil
  243. ities();
  244.                                            ^
  245.   symbol:   variable BenfordSupportCode
  246.   location: class BenfordsLaw
  247. BenfordsLaw.java:94: error: method calculateDistance in class BenfordsLaw cannot
  248.  be applied to given types;
  249.                 double distanceBenford = calculateDistance(distributionBenford,
  250. distributionIdeal);
  251.                                          ^
  252.   required: double[],double[]
  253.   found: double[],double
  254.   reason: actual argument double cannot be converted to double[] by method invoc
  255. ation conversion
  256. BenfordsLaw.java:96: error: cannot find symbol
  257.                 double distanceRandom = calculateDistance(distributionRandom, di
  258. stributionIdea);
  259.                                                                               ^
  260.   symbol:   variable distributionIdea
  261.   location: class BenfordsLaw
  262. 28 errors
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement