teaching machines

CS 145 Lab 4 – Conditionals and Loops

October 17, 2015 by . Filed under cs145, fall 2015, labs.

First, if you have checkpoints left over from last lab, get them inspected during the first 15 minutes of this lab. No credit will be awarded past these 15 minutes.

Don’t forget to work in pairs! Please work with someone that you did not work with last lab.


In this lab, we use logical operators to make our code branch and repeat.

Checkpoint 1

Person A types.

Write and carefully test a method named getOrdinal that takes in an int parameter and returns a String in which the parameter is followed by its correct ordinal suffix: st, nd, rd, or th.

Checkpoint 2

Person B types.

Complete at least two of the following problems. Use loops even when alternative solutions may be feasible.