teaching machines

CS 145: Lab 6 – Conditionals

October 21, 2017 by . Filed under cs1, cs145, fall 2017, labs.

Welcome to lab 6!

If you have checkpoints from the last lab to show your instructor or TA, do so immediately. No credit will be given if you have not already completed the work, nor will credit be given after the first 10 minutes of this lab.

In this lab, we’ll explore conditional statements, which let us execute different actions under different circumstances. Conditional statements make our code sensitive, which is the best way to be.

Checkpoint 1

Person A types.

Head to Practice-It! and log in. Complete the follow exercises:

If you feel like you could use extra practice with the concepts we discuss in this class, keep working away at the problems on Coding Bat and Practice-It! Don’t wait for them to be assigned.

Checkpoint 2

Person B types.

Write a class Ordinal with a main method (to test) and a method named getOrdinal. Have getOrdinal accept an int and return a String representation of that number with its correct ordinal suffix. For example:

System.out.println(getOrdinal(1)); // prints 1st
System.out.println(getOrdinal(2)); // prints 2nd
System.out.println(getOrdinal(3)); // prints 3rd
System.out.println(getOrdinal(4)); // prints 4th
System.out.println(getOrdinal(5)); // prints 5th
System.out.println(getOrdinal(6)); // prints 6th
System.out.println(getOrdinal(7)); // prints 7th
System.out.println(getOrdinal(8)); // prints 8th
System.out.println(getOrdinal(9)); // prints 9th
System.out.println(getOrdinal(10)); // prints 10th
System.out.println(getOrdinal(11)); // prints 11th
System.out.println(getOrdinal(12)); // prints 12th
System.out.println(getOrdinal(13)); // prints 13th
System.out.println(getOrdinal(14)); // prints 14th
System.out.println(getOrdinal(15)); // prints 15th
System.out.println(getOrdinal(16)); // prints 16th
System.out.println(getOrdinal(17)); // prints 17th
System.out.println(getOrdinal(18)); // prints 18th
System.out.println(getOrdinal(19)); // prints 19th
System.out.println(getOrdinal(20)); // prints 20th
System.out.println(getOrdinal(21)); // prints 21st
System.out.println(getOrdinal(22)); // prints 22nd
System.out.println(getOrdinal(100)); // prints 100th
System.out.println(getOrdinal(101)); // prints 101st
System.out.println(getOrdinal(102)); // prints 102nd
System.out.println(getOrdinal(111)); // prints 111th