More Java Prelab

Due by 10am Monday, 18 February 2019

In this prelab, you will tackle some of the non-programming issues related to the second full lab assignment. Please write or type up your solutions, and submit it on Gradescope before 10am on Monday. Late prelabs are not accepted.

Recursion

Work out by hand what the following method will do. If you want to check your answer by running the method using Java, that is fine, but you need to be able to think about recursive methods without running them. Start by computing strange(0), then strange(1), strange(2), and so forth.
public int strange(int x){
    if (x <= 0){
	     return 1;
     } else {
	     return 5 * strange(x-1) - 2;
     }
}
    1. What is the output of System.out.print(strange(3)) ?

Lock Class

  1. Imagine you are writing a class to represent a combination lock (i.e. the kind of lock with a dial you turn to enter numbers). What methods and variables would you need in this class?

Benford's law

Take a look at the Wikipedia entry for Benford's Law. We are going to compute the frequency distribution of digits in some files and see if this distribution (Benford's law) actually holds for them. As part of this, we will be drawing a simple text-based histogram chart based on the frequency of the digits.

  1. Describe the data structures you would need to perform this calculation. (E.g., if you were going to do this by hand, what would you be keeping track of and how?)
  2. Assuming that you have list of integers representing counts and an integer N representing the height of the tallest bar, give an algorithm that would allow you to come up with an integer height of all the bars such that they are between 0 and N units tall and an appropriate proportion of the height of the tallest bar. Note: the counts might be greater or less than N

    For example, if the counts were 1, 2, 4 and N was 20, then you'd make the height of the bar for the count 4 be 20, 2 would be scaled to 10, and 1 would be height 5.

If you adhered to the honor code in this assignment, add the following statement at the top of your prelab.

I have adhered to the Honor Code in this assignment.


Last Modified: February 07, 2019 - Cynthia Taylor, based on material from Benjamin Kuperman & Roberto Hoyle