Copyright © Cay S. Horstmann, Kathleen O’Brien 2009-2014
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
isVowel
method is a stub. Complete it so that it returns true
if letter
consists of a single letter that is a vowel. Otherwise retun false
. Driver: What is your method?WordTester.java
into your project. Run the main
method. Driver: Did all tests pass? If not, what did you need to do to fix your isVowel
method?isVowel
method. Inexperienced programmers commonly test for both upper and lowercase in every branch. If you convert letter to lowercase before you test, you can cut the work in half
String lower = letter.toLowerCase() if (lower.equals("a") return true; else if (some other condition) return true; else return false;
Rewrite your solution using toLowerCase(). Driver: What is your code.
isVowel
even more simply. Let's look at the the contains
method of the String
class
boolean contains(String str) Returns true if and only if this string contains the sequence of char values specified by str.Example
String message = "Hello World"; message.contains("d") returns true message.conrains("x") returns false
isVowel
method using contains.
Your code will only use the contains
method one time. There will be no logical operators (|| or &&). Ask your lab instructor if you can't get it. Driver: What is your implementation of isVowel
using this method? if
statements or the one with contains
? Scribe: tell Why?public boolean fill(int row, int column) { return your expression here; }
for each row and column between 0 and 9, filling in the square with red when the method returns true
.
This class uses a different graphics library than we have been using. That is okay. You are only interested in the fill method. Just ignone all the other code
Your task is to implement the fill
method in various ways in order to generate different patterns. For example, if your fill
method is
public boolean fill(int row, int column) { return !(row == 0 && column == 0); }
then all squares are filled in except the one at (0,0).
In the following exercises, you will be asked to generate various patterns. First write the Boolean expression on a sheet of paper. Driver and scribe take turns for each of the patterns. Then discuss whether your expression is correct. Finally, the driver types in the expression in the program, compiles, and runs. The scribe types in the expression in the report.
Your goal should be to get the correct result in one try. If you find yourself making random changes on the computer, take your hands off the keyboard and start thinking again!
Some of the patterns depend on whether the row or column are even or odd. Remember that n % 2 == 0
is true whenever the integer n
is even.
What is the expression that makes this picture? Remember to write it down first. (Driver)