March 22 Assignment

Please Send Me Your GitHub Username

If you haven’t done so yet, please create a GitHub account and email me your GitHub username. Please follow the directions in the email I sent last night. In particular DO NOT use punctuation in your GitHub username or password.

Note: You can’t clone our shared repo (which you are asked to do below) until I grant you access to the repo.  I can’t grant you access until I have your GitHub username.

Off Campus Students

Please turn on your VPN client. If you haven’t installed the VPN client yet, please check your email for an email informing you about how to install the VPN.

Log onto cs.bridgewater.edu

  • Please log into cs.bridgewater.edu using either terminal (mac users), gitbash (installed with Git for Windows), or putty.

Clone Our Shared Repository

  • Clone our shared GitHub repository following the directions given in the tutorial named Using Git.

Change Your Working Directory to Today’s Homework Directory

  • Run the following ls command on the command line.
$ ls

You will notice that the git clone command created a directory that is named the same as your last name. That directory is our shared repository.

  • Change your working directory so that you are in our shared repository. Replace <your repo name> in the command below with your repository name as shown by the ls command above.
$ cd <your repo name>
  • Run the ls command.
$ ls

You will notice inside our shared repository is a directory named csci101.

  • Please issue the following command to change your working directory to the csci101 directory.
$ cd csci101
  • Run the ls command again. Now you will notice 3 directories named exams, hw, and labs.
$ ls
  • Change your working directory to the hw directory.
$ cd hw
  • Run ls again. Now you will see a whole bunch of directories, one for each lecture.
$ ls
  • Change your working directory to the mar22 directory.
$ cd mar22

This is where you’ll program today’s practice problems.

When coding, abide by the following rules.

  • Work independently.  The only way that you will learn how to code is by hitting roadblocks and self-realizing how to avoid them.
  • Compile often. Do not attempt to code all of this and then compile.  It is just too hard to debug that way.

Program Specifications

  • Using nano create a program file named Practice.java and in it write a program that does the following:
    1. Print your name to standard out (i.e. the screen).
    2. Use a while loop to print the numbers between 1 and 10 (inclusively) to the screen, all on a single line, with spaces between the numbers.
    3. Ask the user for an upper bound and a lower bound.  Use a while loop to print the numbers between the upper and lower bounds (exclusively).
    4. Use a while loop to print the even numbers between 10 and 20 (exclusively) to the screen, all on a single line, with spaces between them.
    5. Use a while loop to print the numbers divisible by 5 between 30 and 50 (inclusively) to the screen, all on a single line, with spaces between them.
    6. Use a while loop to repeatedly ask the user to enter a number.  If the number is odd, print “odd”. Otherwise, print “even”.  If the user enters a negative number then terminate the loop.

That’s all for tonight.

Using Kattis’ Client

Create a Kattis Account

  1. Create an account on open.kattis.com. Choose Log in with e-mail, then choose Sign up for a Kattis account. Use your Bridgewater College email address when creating an account.

Getting the Kattis Client and Config File

  1. Log in to Kattis.
  2. Choose the Help tab, then choose the How to submit link located near the bottom of the page.
  3. Scroll down to the section titled Downloading a configuration file and client and download your personal configuration file and the kattis client.
  4. Open terminal or GitBash and change the working directory to the location of the files you downloaded (perhaps in your download directory). Then use the following command to copy the files to your VM.
scp -i <path to keypair file> <file to transfer> ec2-user@<ip address>:<file to transfer>

Setting Up Your VM

  1. SSH into your VM.
  2. Change the permissions of submit.py to 700.
  3. Create a directory named bin and move submit.py into bin.
  4. Verify that $HOME/bin is in your $PATH.
  5. Rename the kattis config file (e.g. kattisrc.txt) to .kattisrc.

Testing the Script

  1. Navigate to https://open.kattis.com/problems/hello.
  2. Create a program that solves the hello problem in a class named Hello.
  3. Submit your program to Kattis using the following command:
    1. submit.py -p hello -l Java -m Hello Hello.java
  4. Navigate to open.kattis.com with a browser and click on your name in the upper right corner to see if you submitted a correct solution.

	

Variable declarations

  1. Declare a variable named numMinutes that holds a 32 bit whole number and is initialized to the value of the integer read from the keyboard (use a print statement to ask the user to enter a whole number).
  2. Declare a variable named numSeconds that holds a 32 bit whole number and is initialized to 60 times the value stored in numMinutes.
  3. Write code that creates a variable name finished that holds the Boolean value true if the value in numSeconds is greater than or equal to 120 and holds false otherwise.  Print to the screen “Finished: ” followed by the value of the variable finished.
  4. Ask the user to enter an integer and store the integer in a variable named number.  Print to the screen “Is multiple of three: ” followed by true if the value in number is a multiple of three, and false otherwise.
  5. Declare two integers named maxAge and curAge and initialize them using values read from the keyboard (include print statements requesting integer values). Write a statement that creates a variable named overLimit that is set to true if the value of curAge is greater than the value of maxAge, and set to false otherwise.  Print to the screen, “Over the Limit:  ” followed by the value of the variable overLimit.
  6. Declare a variable named average and initialized it to the decimal value read from the keyboard (ask the user to enter the value). Write a block of code that sets a Boolean variable named passing to true if average is greater than 65, otherwise sets passing to false.  Print to the screen “Passed: ” followed by the value of the variable passing.
  7. Ask the user to enter a string from the keyboard and store the string in a variable named str.  Print to the screen “Length: ” followed by the length of str.
  8. Replace all of the instances of the character ‘a’ with the character ‘o’ and print the result to the screen.
  9. Declare a variable named idx and initialize it to the index of the first instance of the character ‘e’ in the string str.  Print to the screen “Index: ” followed by the value stored in idx.

Conversions & Declarations

  • Answer all questions in prior reviews.
  • Count from 0 to 20 (base 10) in binary.
  • Convert 250 (in base 10) to base 2.
  • Convert 11001100 (base 2) to a decimal value.
  • Declare a variable named code and initialize it to the character X.
  • Declare a variable named mean and initialize it to the value 80.5.
  • Assume you have the character X saved in a variable named code and 80.5 stored in a variable named mean. Write a print statement using println and the variables to print the following:
    • Code: X, Mean: 80.5
  • Assume you have the character X saved in a variable named code and 80.5 stored in a variable named mean. Write a print statement using printf and the variables to print the following:
    • Code: X, Mean: 80.5
  • Declare a variable named middleName and initialize it with the string of characters “Joe”.
  • Assume you have a variable named middleName that holds a string of characters. Write a statement that prints the length of the String.
  • Assume you have a variable named middleName that holds a string of characters. Write a statement that stores the length of the String in a variable named length.
  • Read an integer from the keyboard and store it in a variable named height.
  • Read a floating point value from the keyboard and store it in a variable named area.
  • Read a string from the keyboard and store it in a variable named title.