CSCI 151 - Prelab 1

Due 9am, Monday 12 Sep 2016

In this prelab, you will be working on some of the isses related to the first full lab assignment. Please write up or type up your solutions and hand in a paper copy before 10am on Monday. Remember: no late prelabs allowed!

Unlike most of the other labs, this one will consist of a number of small programming assignments to give you a chance to become familar with programming in Java.

Return to the Pyramids

You may recall from 150 having to draw a Pyramid out of bricks. Well, this time I want you to build a pyramid out of stars! They will be symmetrical and look like:

  1. Given a height N, give the loops needed to print a pyramid of that height. You may do this in Java, Python, or even pseudocode

HiLo guessing game

You and your friend (the computer) will play a guessing game. One of you will pick a number between 1 and 1000. The other one will guess numbers and the other will tell them if they guessed correctly or were too high/low.

  1. Describe the logic needed to ensure that a user types in a guess between 1 and 1000


  1. Describe how you could accurately determine the number of lines in a text file

You'll also want to think about different ways you might be able to match words on that line. (i.e., do some String matching)

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.

Last Modified: August 22, 2016 - Roberto Hoyle, based on material from Benjamin Kuperman