teaching machines

CS 145 Lab 1 – Scanner

September 8, 2019 by . Filed under cs1, cs145, fall 2019, labs.

Welcome to the first lab of CS 145!

Protocol

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:

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:

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:

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.

Apgar

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

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

Division

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

Dividend:⎵100
Divisor:⎵6
Answer:⎵16R4

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:

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