teaching machines

CS 145 Lab 1 – Scanner

Welcome to the first lab of CS 145!


Lab is a time intended for you to work on programming exercises in a low-stakes environment and with lots of help at your disposal. Read each of these out loud with your lab partner and check them off to acknowledge your understanding:

  • You complete a few checkpoints, which consist of short programming exercises.
  • Questions are always fair game. Your instructor and teaching assistant are here to help.
  • You work with a partner of your choosing, but this must be a different person each week. Talking through technical matters with other human beings is a key part of lab.
  • Groups of three are not allowed except by permission from the instructor.
  • You work at one computer only.
  • One person types for the first exercise. The other for the second checkpoint. And so on.
  • You must show your work to either your instructor or your teaching assistant to receive credit.
  • Both you and your partner must be present during checkoff time to receive credit.
  • Checkpoints are only checked during lab, not during office hours or over email.
  • If you don’t finish your checkpoints during a lab meeting, you can complete your work before next lab and get checked off during the first 10 minutes of the subsequent lab. No credit is granted if the work is not already complete before lab starts.

Many of these rules were crafted out of experiences from earlier offerings of this course. These are designed to maximize the number of passing grades at the end of the semester.

One of you is person A and the other is person B. You pick!

GitLab and IntelliJ

Person A, take control of the machine!

Your code this semester is stored in a project hosted on GitLab. You should have already set this up when you completed homework 0. If you haven’t already cloned to the H: drive, let’s do that now by following these steps:

  • Make a new, empty directory on the H: drive. Name it cs145.
  • Open IntelliJ 2019.2.
  • At the dialog, choose Check out from Version Control. If you’ve missed the dialog, you can also click New / Project from Version Control / Git.
  • For URL, enter https://gitlab.com/cs1_2019c/USERNAME, replacing USERNAME with your UWEC username.
  • For Directory, navigate to the directory you made earlier.
  • Click Clone, which will start downloading.
  • Open the project when prompted.

If you have already cloned to the H: drive, then open IntelliJ and open your project.

Once the project is open, follow these steps to create some packages to organize the code you write in lab:

  • In the Project panel, expand cs1_2019c_template and src.
  • Right click on src and make a new package named labs. Note that this uses all lowercase letters. In general, match the CaSe of the example text that you see for the entirety of this course.
  • Right click on labs and make a new package named lab01. Note the leading 0. We will eventually get into two digits, and the leading 0 will ensure that packages’ chronological order is the same as their dictionary order.

Checkpoint 1

Person B, take control of the machine! In this first checkpoint, we’ll write a couple of programs that directly follow the patterns of programs we’ve seen in lecture.


First, let’s write a program that calculates a newborn baby’s health using the Apgar test. Follow these steps:

  • Create a class named Apgar in lab01.
  • Give the class a main method.
  • Prompt the user five times for the five metrics, and store the user input in variables.
  • Output the Apgar score.

If you run into difficulties, call upon your instructor or teaching assistant. Otherwise, move on to the next program.


Second, reverse engineer the following console interaction to write a program that computes the quotient and remainder in a division problem:


Where you see ⎵, insert a space character. Where you see text formatted like foo, the user inputs a value.

Write your program in a new class named Division.

After both classes are working, show your work to your instructor or teaching assistant, and they will mark this checkpoint complete. If your instructor and TA are working with others at the moment, and you are confident that you’ve satisfactorily completed this checkpoint, please move on to the next checkpoint and catch them when they become available.

Checkpoint 2

Person A, take control of the machine!

Let’s write a program that prompts the user for two colors and mixes them together. This sort of routine is used all the time when resizing or transitioning between images.

A color is often represented in a computer with a triplet integers: a red component, a green component, and a blue component, each in the range [0, 255]. These three intensities combine to produce all the possible colors that our monitors can display.

To mix two colors, we compute a weighted average of their red components, green components, and blue components separately to produce a new triplet.

Follow these steps to write your color-mixing program:

  • Prompt the user for a first color and store the inputs from the Scanner in three ints, one for each of the color’s red, green, and blue intensities. Assume the color intensities are in [0, 255]. Pick good names for your variables!
  • Prompt the user for a second color and store the inputs from the Scanner in three ints. Pick good names for your variables!
  • Prompt the user for a proportion or weight by which to mix the colors. Assume the user enters a number in [0, 1].
  • Compute the blend color as a weighted average of the input colors. Mix the reds, greens, and blues independently. If the proportion is 0.1, then the mix is 10% of the second color and 90% of the first. For example, If the red intensity of the first color is 50, and the red intensity of the second color is 100, then the red intensity of the blended color is 10% of 100 and 90% of 50, which is 55. Store the results of your mixing in three new int variables.
  • Print out the mixed intensities and compare them against the little tester utility below.

Show your working solution to your instructor or teaching assistant. Once you are checked off, you are free to leave.


Leave a Reply

Your email address will not be published. Required fields are marked *