I want to recommend a list of hands-on projects for you to practice independently. Working through these projects will definitely help you deepen your understanding of the basic Java programming concepts described in this book.
Project A
Step 1
public int getHeight() - Returns this rectangle’s height.
public int getWidth() - Returns this rectangle’s width.
public int getX() - Returns this rectangle’s x-coordinate.
public int getY() - Returns this rectangle’s y-coordinate.
public String toString() - Returns a string representation of this rectangle, such as:
Step 2
The two contains() methods return a Boolean state of whether the given Point or coordinates lie inside the bounds of this Rectangle or not. For example, a rectangle with [x=2, y=5, width=8, height=10] will return true for any point from (2, 5) through (10, 15) inclusive, which means the edges are included.
Project B
Design a program to find the number of days between the current day and the user’s birthday, given four input values.
Your next birthday is in 105 days, counted from today.
Project C
The game rule is this: you start with 21 sticks, and two players take turns either taking one or two sticks. The player who takes the last stick loses. Can you design a program to simulate one of the two players in the game? One player is a user and the other player is the computer.
Project D
Write a method named hasVowel() that returns whether a string has included any vowel (a single-letter string containing a, e, i, o, or u, case-insensitively).
Project E
Write a method named gcd() that accepts two integers as parameters and returns the greatest common divisor (GCD) of the two numbers. The GCD of two integers a and b is the largest integer that is a factor of both a and b. The GCD of any number and 1 is 1, and the GCD of any number and 0 is the number.
One efficient way to compute the GCD of two numbers is to use Euclid’s algorithm, which states the following:
GCD(A, B) = GCD(B, A % B)
GCD(A, 0) = Absolute value of A
gcd(24, 84) returns 12
gcd(105, 45) returns 15
gcd(0, 8) returns 8
Project F
Write a method named toBinary() that accepts an integer as a parameter and returns a string of that number’s representation in binary. For example, the call of toBinary(42) should return “101010”.
Project G
Use the four numbers on the following cards to create a math expression that equals 24. Each card can be used only once. Treat ace as a number “1”. You may use +, -, *, /, ( and ) in the math expression. Please find all possible answers.