For each problem, create a class named ProblemX,
where X is the problem number
(e.g., Problem1.java).
Write corresponding JUnit test classes named
ProblemXTest.
Each method must include proper Javadoc comments describing the (1) purpose of the method, (2) parameters, and (3) return value.
Note: look out for edge cases for your conditional statements! If your code is failing the autograder, there are two issues: (1) your code is likely incorrect and (2) your test cases are not comprehensive.
You may not use anything beyond Chapter 2.1. This includes but is not limited to:
Any violation results in a score of 0 on the lab.
Please contact a staff member if you are unsure as to whether you're allowed to use something.
Note 1: Updated description to talk about handling edge cases.
Design the String userId(String f, String l, int y) method that computes a user ID
based on three given values: a non-empty first name, a non-empty last name, and a birth year \(y \geq 1900\). A user ID is
calculated by taking the first five letters of the last name, the first letter of the first
name, and the last two digits of the birth year, and combining the result. Your method should,
therefore, receive two String parameters and an int. You are not allowed to convert
the year to a String in order to retrieve its last two digits. Below are some test cases.
userId("Joshua", "Crotts", 1999) => "CrottJ99"
userId("Katherine", "Johnson", 1918) => "JohnsK18"
userId("Peter", "Perry", 2003) => "PerryP03"
userId("Fred", "Fu", 1957) => "FuF57"
Files to Submit: Problem1.java, Problem1Test.java
Design the int max(int x, int y, int z) method that returns the maximum of three
integers x, y, and z. Do not use any built-in
(Math library) methods. If you have a case where two of the integers are the largest or all of the integers are the same, it does not matter which you return.
Files to Submit: Problem2.java, Problem2Test.java
Design the String popChars(String s, char c, char d) method, which receives a
string s and two characters c and d. The method removes
c if s starts with c, and removes d if the
second character of s is d. The remainder of the string is the same.
Files to Submit: Problem3.java, Problem3Test.java
This question is worth 10 extra credit points. Even though this question is extra credit, you should still do it! You are required to know the corresponding material (i.e., how to use the compareTo string method) for PSet2, so it serves as good practice. We make this extra credit because it may not have been covered in lecture. Even so, it is in the book and the lecture slides!
Design the String middleString(String a, String b, String c) method, which receives three strings a, b, and c, and returns the string that is "in between" the others in terms of their lexicographical content. You cannot sort the strings or use an array. You may assume that a, b, and c are all distinct strings.
Note: the given strings can be in any arbitrary order; it is your job to determine which string is in the middle lexicographically.
Hint: use compareTo.
Files to Submit: Problem4.java, Problem4Test.java