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:
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!
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:
cs145
.https://gitlab.com/cs1_2019c/USERNAME
, replacing USERNAME
with your UWEC username.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:
cs1_2019c_template
and src
.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.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.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:
Apgar
in lab01
.main
method.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:
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.
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:
Scanner
in three int
s, 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!Scanner
in three int
s. Pick good names for your variables!int
variables.Show your working solution to your instructor or teaching assistant. Once you are checked off, you are free to leave.
Comments