Natural Prestidigitation Assignment How To

We recommend that you review this guide prior to starting work on this assignment.

Frequently Asked Questions:


Possible Plan

We do not provie you with any starter code for this assignment. Nevertheless, you should still snarf the assignment digit for the data directory and an empty class file. Below a suggested decomposition of the problem into functions that you can implement. However, you can ignore the framework below and create whatever methods you like as long as you produce the same output in the end.
  1. Write a method nthDigit. nthDigit(n,num) finds the nth highest order digit of num, i.e., the nth digit from the left. We take the leftmost digit to be the 0th. nthDigit should evaluate to 0 for digits beyond the "end" of the number. For example:

    When computing

  2. Write a method nthDigitTally, using nthDigit. nthDigitTally(n, nums) returns a tally of frequencies of 0–9 as the nth digits of all the numbers in nums.

    Here's a sample test case. These are enrollments in Research Triangle Park colleges and universities in Fall 2000 (thanks to the "Research Triangle Regional Partnership" website: http://www.researchtriangle.org/data/enrollment.html).

    InstitutionEnrollment
    Duke University 12176
    North Carolina Central University 5476
    Louisburg College (Junior College) 543
    Campbell University 3490
    University of North Carolina at Chapel Hill 24892
    North Carolina State University 28619
    Meredith College 2595
    Peace College 603
    Shaw University 2527
    St. Augustine's College 1465
    Southeastern Baptist Theological Seminary 1858
    Assume the variable enrollments contains the enrollment numbers from that table. Then:

    nthDigitTally(0, enrollments)[0,3,4,1,0,2,1,0,0,0]

  3. Write a method readNumbers that reads whitespace-separated integers from a Scanner and returns a list of the numbers suitable as input to nthDigitTally. Here's the university enrollment data from above:
    12176
    5476
    543
    3490
    24892
    28619
    2595
    603
    2527
    1465
    1858
    
    From this, readNumbers should produce the list [12176, 5476, 543, 3490, 24892, 28619, 2595, 603, 2527, 1465, 1858].

  4. Finally, compose your main method to prompt the user for the number n and to choose a file for the data set. The program should tally the nth digits of the numbers in the data set and print out a table of the results. For example, given that n=0 and the following file: 12176 5476 543 3490 24892 28619 2595 603 2527 1465 1858 Your program should print: 0s: 0 (0%) 1s: 3 (27%) 2s: 4 (36%) 3s: 1 (9%) 4s: 0 (0%) 5s: 2 (18%) 6s: 1 (9%) 7s: 0 (0%) 8s: 0 (0%) 9s: 0 (0%)

Enrichment


Last modified: Wed Feb 2 14:46:37 EST 2011