Decisions
Categories:
2 minute read
Background
CodingBat is a free site of live problems to build skill in Java and/or Python. It was created by Nick Parlante, who is Computer Science lecturer at Stanford. The name “CodingBat” was based on the Greek word “bat” meaning “this domain was available” (or so they say).
Objectives
- Practice writing small methods with conditionals and decisions.
- Explore combined conditionals as substitutes for decision statements.
- Observe the range of test cases needed to test decision statements.
Key Terms
- unit test
- A single example of running a small program unit, often a method.
- expected value
- The correct value a program should return for a unit test (aka test case).
- actual value
- The value a program actually returns for a unit test.
- simplified code or boolean expression
- A version of a piece of code that is less complicated or shorter than the original.
Part 0: Account Setup
- Go to codingbat.com and create an account (click the link on the upper right).
- Please use your JMU email when setting up your account.
- After logging in, click the “prefs” link (upper right) and “share to” your instructor’s email (
duanzx@jmu.edu
,stewarmc@jmu.edu
,wangid@jmu.edu
, orweikleda@jmu.edu
) so you will get credit. - Also make sure your name is entered as shown: Last, First
Part 1: Warm Up
As you begin to work CodingBat’s logic problems, you might find the CodingBat Boolean Logic page or their videos helpful:
Work through the following problems (all from Warmup-1 ). As you work through the problems notice that all of these have solutions available to you. Spend about 5 minutes trying each problem, before you look at the solution. When you are trying the problem and get the results, look at the test cases displayed by codingbat. Identify the expected and actual values. Notice that you may pass several tests, but not all of them. Unlike straight line code without decisions, conditionals and decision statements take a variety of test cases to make sure they work.
Part 2: String methods
Many of the problems on codingbat require you to use String methods that you may not yet have encountered. Check out especially:
Part 3: Warm-up with strings
Work through some of the Warmup-1 problems that require String methods:
Part 4: Problem Solving
- Solve the following problems (all from Logic-1 problems):
- Solve the following problems ( from Logic-2 problems):