Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class BenfordsLaw{
- public static int calculateLeadingDigit(int number) {
- int absoluteNumber = Math.abs(number);
- while(absoluteNumber >= 10);
- {
- absoluteNumber=(absoluteNumber / 10);
- }
- return absoluteNumber; //represents leading digit
- }
- public static double[] generateBenfordNumbers(double initialAmount, double growthRate, int numberPeriods) {
- for(i=0;i=numberPeriods;i++){
- double growthNumber = (initialAmount * (1+growthRate)); //generate each of the growth numbers
- }
- return growthNumber;
- }
- public static double[] calculateLeadingDigitProportions(double[] numbers) {
- int arraySize = numbers.length; //number of values in the array
- int countZero = 0;
- int countOne = 0;
- int countTwo = 0;
- int countThree = 0;
- int countFour = 0;
- int countFive = 0;
- int countSix = 0;
- int countSeven = 0;
- int countEight = 0;
- int countNine = 0;
- for(i=0;i < arraySize; i++){
- int leadingDigit = calculateLeadingDigit((int)numbers[i]);
- if(leadingDigit == 0) {
- countZero++;
- }
- if(leadingDigit == 1) {
- countOne++;
- }
- if(leadingDigit == 2) {
- countTwo++;
- }
- if(leadingDigit == 3) {
- countThree++;
- }
- if(leadingDigit == 4) {
- countFour++;
- }
- if(leadingDigit == 5) {
- countFive++;
- }
- if(leadingDigit == 6) {
- countSix++;
- }
- if(leadingDigit == 7) {
- countSeven++;
- }
- if(leadingDigit == 8) {
- countEight++;
- }
- if(leadingDigit == 9) {
- countNine++;
- }
- }
- double[] array = {(countZero/arraySize),(countOne/arraySize),(countTwo/arraySize),(countThree/arraySize),(countFour/arraySize),(countFive/arraySize),(countSix/arraySize),(countSeven/arraySize),(countEight/arraySize),(countNine/arraySize)};
- return array;
- }
- public static double calculateDistance(double[] a, double[] b) {
- int sizeArray = a.length;
- double total = 0;
- for(i=0; i < sizeArray; i++) {
- total = total + Math.pow((a[i]-b[i]),2);
- }
- double distanceEuclidian = Math.sqrt(total);
- return distanceEuclidian;
- }
- public static void main(String[]args){
- double initialAmount = 100;
- System.out.println("The starting amount is"+initialAmount);
- double numberSteps = 1000;
- System.out.println("The number of periods is"+numberSteps);
- double rateGrowth = 0.01;
- System.out.println("The growth rate is"+rateGrowth);
- double[] benfordSequence = generateBenfordNumbers(initialAmount, rateGrowth, numberSteps);
- double[] randomNumbers = BenfordSupportCode.generateRandomNumbers(1000);
- //generate array of 1000 numbers
- double[] distributionBenford = calculateLeadingDigitProportions(benfordSequence);
- double[] distributionRandom = calculateLeadingDigitProportions(randomNumbers);
- //step 3 of question 6, calling method to calculate distribution
- for(i=0;i<10;i++){
- System.out.println("For Benford, the distribution of leading digit" + i + "is" + distributionBenford[i]);
- }
- for(i=0;i<10;i++){
- System.out.println("For random generation, the distribution of leading digit" + i + "is" + distributionRandom[i]);
- }
- double distributionIdeal = BenfordSupportCode.getBenfordProbabilities();
- double distanceBenford = calculateDistance(distributionBenford, distributionIdeal);
- System.out.println("The distance of the exponential growth group is " + distanceBenford);
- double distanceRandom = calculateDistance(distributionRandom, distributionIdea);
- System.out.println("The distance of the exponential growth group is " + distanceRandom);
- }
- }
- BenfordsLaw.java:11: error: cannot find symbol
- for(i=0;i=numberPeriods;i++){
- ^
- symbol: variable i
- location: class BenfordsLaw
- BenfordsLaw.java:11: error: cannot find symbol
- for(i=0;i=numberPeriods;i++){
- ^
- symbol: variable i
- location: class BenfordsLaw
- BenfordsLaw.java:11: error: cannot find symbol
- for(i=0;i=numberPeriods;i++){
- ^
- symbol: variable i
- location: class BenfordsLaw
- BenfordsLaw.java:14: error: cannot find symbol
- return growthNumber;
- ^
- symbol: variable growthNumber
- location: class BenfordsLaw
- BenfordsLaw.java:29: error: cannot find symbol
- for(i=0;i < arraySize; i++){
- ^
- symbol: variable i
- location: class BenfordsLaw
- BenfordsLaw.java:29: error: cannot find symbol
- for(i=0;i < arraySize; i++){
- ^
- symbol: variable i
- location: class BenfordsLaw
- BenfordsLaw.java:29: error: cannot find symbol
- for(i=0;i < arraySize; i++){
- ^
- symbol: variable i
- location: class BenfordsLaw
- BenfordsLaw.java:30: error: cannot find symbol
- int leadingDigit = calculateLeadingDigit((int)numbers[i]
- );
- ^
- symbol: variable i
- location: class BenfordsLaw
- BenfordsLaw.java:68: error: cannot find symbol
- for(i=0; i < sizeArray; i++) {
- ^
- symbol: variable i
- location: class BenfordsLaw
- BenfordsLaw.java:68: error: cannot find symbol
- for(i=0; i < sizeArray; i++) {
- ^
- symbol: variable i
- location: class BenfordsLaw
- BenfordsLaw.java:68: error: cannot find symbol
- for(i=0; i < sizeArray; i++) {
- ^
- symbol: variable i
- location: class BenfordsLaw
- BenfordsLaw.java:69: error: cannot find symbol
- total = total + Math.pow((a[i]-b[i]),2);
- ^
- symbol: variable i
- location: class BenfordsLaw
- BenfordsLaw.java:69: error: cannot find symbol
- total = total + Math.pow((a[i]-b[i]),2);
- ^
- symbol: variable i
- location: class BenfordsLaw
- BenfordsLaw.java:81: error: method generateBenfordNumbers in class BenfordsLaw c
- annot be applied to given types;
- double[] benfordSequence = generateBenfordNumbers(initialAmount,
- rateGrowth, numberSteps);
- ^
- required: double,double,int
- found: double,double,double
- reason: actual argument double cannot be converted to int by method invocation
- conversion
- BenfordsLaw.java:82: error: cannot find symbol
- double[] randomNumbers = BenfordSupportCode.generateRandomNumber
- s(1000);
- ^
- symbol: variable BenfordSupportCode
- location: class BenfordsLaw
- BenfordsLaw.java:87: error: cannot find symbol
- for(i=0;i<10;i++){
- ^
- symbol: variable i
- location: class BenfordsLaw
- BenfordsLaw.java:87: error: cannot find symbol
- for(i=0;i<10;i++){
- ^
- symbol: variable i
- location: class BenfordsLaw
- BenfordsLaw.java:87: error: cannot find symbol
- for(i=0;i<10;i++){
- ^
- symbol: variable i
- location: class BenfordsLaw
- BenfordsLaw.java:88: error: cannot find symbol
- System.out.println("For Benford, the distribution of lea
- ding digit" + i + "is" + distributionBenford[i]);
- ^
- symbol: variable i
- location: class BenfordsLaw
- BenfordsLaw.java:88: error: cannot find symbol
- System.out.println("For Benford, the distribution of lea
- ding digit" + i + "is" + distributionBenford[i]);
- ^
- symbol: variable i
- location: class BenfordsLaw
- BenfordsLaw.java:90: error: cannot find symbol
- for(i=0;i<10;i++){
- ^
- symbol: variable i
- location: class BenfordsLaw
- BenfordsLaw.java:90: error: cannot find symbol
- for(i=0;i<10;i++){
- ^
- symbol: variable i
- location: class BenfordsLaw
- BenfordsLaw.java:90: error: cannot find symbol
- for(i=0;i<10;i++){
- ^
- symbol: variable i
- location: class BenfordsLaw
- BenfordsLaw.java:91: error: cannot find symbol
- System.out.println("For random generation, the distribut
- ion of leading digit" + i + "is" + distributionRandom[i]);
- ^
- symbol: variable i
- location: class BenfordsLaw
- BenfordsLaw.java:91: error: cannot find symbol
- System.out.println("For random generation, the distribut
- ion of leading digit" + i + "is" + distributionRandom[i]);
- ^
- symbol: variable i
- location: class BenfordsLaw
- BenfordsLaw.java:93: error: cannot find symbol
- double distributionIdeal = BenfordSupportCode.getBenfordProbabil
- ities();
- ^
- symbol: variable BenfordSupportCode
- location: class BenfordsLaw
- BenfordsLaw.java:94: error: method calculateDistance in class BenfordsLaw cannot
- be applied to given types;
- double distanceBenford = calculateDistance(distributionBenford,
- distributionIdeal);
- ^
- required: double[],double[]
- found: double[],double
- reason: actual argument double cannot be converted to double[] by method invoc
- ation conversion
- BenfordsLaw.java:96: error: cannot find symbol
- double distanceRandom = calculateDistance(distributionRandom, di
- stributionIdea);
- ^
- symbol: variable distributionIdea
- location: class BenfordsLaw
- 28 errors
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement