Lab 2: CodingBat Logic¶
CodingBat.com is a free site of live problems to build skill in Java and/or Python. CodingBat was created by Nick Parlante, who is Computer Science lecturer at Stanford.
Learning Objectives¶
After completing this lab, you should be able to:
- Write short methods that include conditional and logic expressions.
- Apply combined conditionals as substitutes for decision statements.
- Describe the range of test cases needed to test decision statements.
Note
Each of these problems require you to write a short method.
The method definition (starting with the keyword public
) is provided.
None of these problems use System.out
or System.in
.
Instead, each method must return
the result based on the parameter values.
Account Setup¶
Your lab will be graded directly in CodingBat. Please do the following to set up your account:
-
Open the Create Account page in a new tab (so you can keep reading these instructions).
-
Enter your JMU email address and a password you can remember for the CodingBat site.
-
After logging in, open Account Settings and enter your instructor's email address under Teacher Share (see table below).
-
In the Memo textbox, enter your name as "Last name, First name" (Ex:
Watson, Emma
).
Instructor | Email Address |
---|---|
Dr. Duan | duanzx@jmu.edu |
Dr. Mayfield | mayfiecs@jmu.edu |
Dr. Shrestha | shrestcx@jmu.edu |
Dr. Wang | wangid@jmu.edu |
Dr. Weikle | weikleda@jmu.edu |
Warm-Up Problems¶
Solve the following problems from the Warmup-1 category. All of these problems have solutions available to you. Spend about five minutes trying each problem before you look at the solution.
When you submit your code, look at the test cases displayed by CodingBat. Identify the expected and actual values. Notice that you might pass several tests, but not all of them. Unlike sequential code, conditionals and decision statements require many test cases to make sure they work.
Solutions
Video explanations of the following Warmup-1 problems are available:
- Solution Video 1: sumDouble, sleepIn, monkeyTrouble
- Solution Video 2: close10, in3050, loneTeen
Logic Problems¶
Solve the following problems from the Logic-1 category.
Solve the following problems from the Logic-2 category.
Note
As you work on these problems, you might find CodingBat's help page useful:
If you finish the lab early (and have extra time), try solving other problems in Logic-1 and Logic-2.