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.

© 2021 – 2024, Eric. All rights reserved.