CS 151 - Introduction to Data Structures

Lab 1

Getting logged in and set up, some Java

UNIX

Find a lab machine: log in using the credentials you should have received from Davis Diaz (ddiaz@brynmawr.edu). (See Lab Computers on the class web site for login directions.)
  1. Change your password. To do so:
    1. Open a terminal window: tap on the 3x3 grid of dots in the lower left corner, then tap on "terminal" (or tap on the right mouse button and select "terminal" in the popup).
    2. In the terminal window you opened above enter
      		passwd 
      	
      You will be asked to enter your current password, then enter a new password twice. Unix will NOT show any indication of your typing (other that when you hit return). This is by design.
  2. Make a directory for holding all of your work this semester.
    1. In the terminal window you just opened:
    2. Make sure you are in your home directory (more on this next week).
      cd ~ 
    3. create a new directory
      mkdir CS151
The lab machines use a shared file system so it does not matter what machine you are at, your files will always be available.

Start VSC

  1. Ont eh machines in the lab, there is usually an VSC icon along the left edge. It is blue and sort of a sideways triangle with some extensions. Hover the mouse and it should say "Visual studio code". If you cannot find that icon, then in the bottom left is a 3x3 grid of dots. Click on that then look through the screens until you find Visual Studio Code. (It is usually on the last screen.)
  • Every time you start VSC on the machines in the lab Check to confirm that at least the following extension packs are installed
    1. Java Extension Pack
    2. Print Code
    3. Code Runner
    (VSC extensions install in a place that is unique to each lab computer, so you need to check every time you start. Also, even if you always use the same machine you should check; someone could delete extensions.)

    To check the installation, tap on the 'square with the top right quadrant slightly moved' icon on the far left of the VSC screen). Look through the 'enabled' list (just to the right of the icon) for the extensions listed above. If they are not installed tap in the search bar (above the enabled list) and enter an extension name. Tap and follow on screen directions to install.
  • During the installation of the Java Extension Pack, if Java is not installed on your machine you will prompted to install it. (Java is installed on every lab machine as of the writing Aug 24, 2022.)
  • In the initial VSC window (it should say "Welcome" or "Getting Started") tap on "Open ... ". Or from the file menu, select "open ..." (do not use "open workspace ..." or "open folder ...").
    1. Within the popup that just appeared navigate to the CS151 directory you just made.
    2. tap on "new folder" (in lower left (Mac) or upper left (Windows)) -- Do NOT simply open the CS151 folder then create a new folder inside, VSC treats doing so as something very different.
    3. Name your new folder "Lab1"
    4. Make sure the folder you just created is highlighted then Tap on "open".
  • The left column of the VSC window should now say "Explorer" at the top. Just below that should be an entry for Lab1 (in bold type).
  • Create a new file "HelloWorld.java"
    1. Tap on the document with a '+' icon to the right of "Lab1". When you hover over this icon it should say "New File".
    2. type "HelloWorld.java"
  • Tap in the HelloWorld.java tab that should have just appeared.
  • Write a complete java implementation of a "hello world" program. You may put everything in the Main method
  • Run your program (to run do the following).
    1. Tap on the insect and right pointing triangle on the left edge of the screen
    2. Tap on "Run with Java" (Alternately tap on "run" that should have appeared just above you main method.)
      You will only get this behavior if the Java Extension Pack is properly installed.
  • More Java

    1. Modify your hello world program to print out "Hello World" and the count (ie "Hello World 1", "Hello World 2") a lot of times. (At least 610). USE A LOOP.
    2. Run your program
    3. Further modify your program to print Hello world on only even numbers.

    Sieve of Eratosthenes

    This sieve of Eratosthenes is a method first described by an ancient Greek person for finding prime numbers. According to Wikipedia the Sieve works by
    iteratively marking as composite (i.e., not prime) the multiples of each prime, starting with the first prime number, 2. The multiples of a given prime are generated as a sequence of numbers starting from that prime, with constant difference between them that is equal to that prime. This is the sieve's key distinction from using trial division to sequentially test each candidate number for divisibility by each prime. Once all the multiples of each discovered prime have been marked as composites, the remaining unmarked numbers are primes.
    Write a program to determine the prime numbers up to 1000 using this method. At the end, print the primes you found.

    My take on the sieve starts by assuming that every number is prime. Then do the following loop:

    	1. Find the smallest number you have not yet considered that is still marked as prime. (Start at 2)
    	2. Mark every multiple of this number (up to the largest you care about) as not prime
    	3. Return to step 1.
    		
    Note that this method requires only addition and memory to determine the set of prime numbers.

    A suggested approach: start by allocating an array of booleans of size 1000. Initially make every element of the array true (that is, assume that everything is a prime). Then mark things as false as you determine that they are composite (not prime).

    What to Hand In

    The final version of your hello world program and as far as you got on the Sieve.

    Send your programs to gtowell@brynmawr.edu. You can cut / paste your code into the email, attach your code, take a photo of your screen. Almost anything so that I can see you work. (Labs will be like that.)

    Final comment

    I do not expect comments (or even particularly good style) for programs written in labs.