Overview · Learning Goals · Files · Rules · Tasks · Testing · Checklist
In Project A you will build a small library of static methods involving numbers, strings, and arrays.
Each method solves a separate programming problem. Together, the methods provide practice with Java syntax, loops, conditionals, arrays, strings, arithmetic operations, and algorithmic problem solving.
By completing this project, you should become more comfortable with:
Download both files and place them in the same directory.
You will implement your solutions in:
Project_A.java
The file:
Project_A_Tester.java
provides a collection of tests that you can run while developing your project.
Scanner, command-line arguments, or another input mechanism.
charAt(int index).
Implement:
public static int reverseInt(int n)
Reverse the digits of a non-negative integer.
For example:
reverseInt(123) → 321
reverseInt(5) → 5
reverseInt(0) → 0
%) and division (/) operators.
Do not convert the integer to a String.
Remember that:
int digit = n % 10;
n = n / 10;
allows you to remove and process one digit at a time.
Implement:
public static String reverseString(String input)
Return a new String containing the characters of
input in reverse order.
For example:
reverseString("abc") → "cba"
charAt(index) allows you to access an
individual character in a String.
Implement:
public static boolean isPalindrome(String input)
Determine whether the String reads the same forwards and backwards.
For example:
isPalindrome("racecar") → true
isPalindrome("hello") → false
Implement:
public static int countVowels(String input)
Count and return the number of vowels in the String.
For example:
countVowels("hello") → 2
countVowels("AEiou") → 5
Examine the String one character at a time using
charAt(i).
Implement:
public static int[] reverseArray(int[] values)
Reverse the elements of the original array in place.
For example:
{1, 2, 3, 4} → {4, 3, 2, 1}
Implement:
public static int[] swap(int a, int b)
Return a two-element array containing the values in reversed order.
For example:
swap(3, 7) → {7, 3}
Implement:
public static int[] concatenateArrays(int[] a, int[] b)
Return a new array containing all elements of
a followed by all elements of b.
For example:
a = {1, 2}
b = {3, 4}
result = {1, 2, 3, 4}
Implement:
public static int checkCase(String input)
Determine whether the letters in a String are all uppercase, all lowercase, or mixed.
The method should return:
1 if the String is all uppercase0 if the String is all lowercase-1 if the String contains mixed caseFor example:
checkCase("HELLO") → 1
checkCase("hello") → 0
checkCase("HeLLo") → -1
'A' through 'Z' and
'a' through 'z'.
Implement:
public static boolean hasAdjacentValue(int[] nums, int target)
Determine whether target occurs in two adjacent
positions in the array.
For example:
hasAdjacentValue({1, 2, 2, 3}, 2) → true
hasAdjacentValue({1, 2, 2, 3}, 3) → false
nums[i] with nums[i + 1],
be careful that i + 1 does not move beyond the end
of the array.
Implement:
public static boolean hasDuplicates(int[] values)
Return true if any value appears more than once
in the array and false otherwise.
For example:
hasDuplicates({1, 2, 3}) → false
hasDuplicates({1, 2, 1}) → true
Place Project_A.java and
Project_A_Tester.java in the same directory.
Compile both files:
javac Project_A.java Project_A_Tester.java
Then run the tester:
java Project_A_Tester
The tester will report which supplied tests pass and which fail, followed by a summary of the number of tests passed.
Project_A.java compiles without errors.
charAt(int index) from the String class.
reverseInt reverses digits numerically rather than
converting the integer to a String.
reverseArray reverses the original array in place
without allocating another array.
Project_A_Tester and investigated
any failing tests.