(1) String Matching

Download the class called CompareStrings.java and complete the match() method which will RECURSIVELY determine whether or not two strings match. The matching process should allow "wild cards". A '@' character will match with any other character and a '*' character will match with zero or more characters of any type. As a hint, try to first get your code working without wild cards. Then get it working with the '@' character and lastly with the '*' character. Note that you MAY NOT use any kind of while loops or for loops in your code. Remember to break the Strings apart one letter at a time and that the recursive call should take one or two smaller strings as parameters. The charAt(0) method for Strings returns the first character of the string, the length() method returns the size of the string and the substring(1) method returns the string without the first character. For simplicity, you can assume that wild characters will only appear in the second string and not in the receiver first string. Remember, your method MUST be recursive. Test your method thoroughly and make sure to hand this testing in.

public class CompareStrings {
public static boolean match(String x, String y) { // Complete this method
public static void main(String args[]) {
System.out.println(match("hello", "hello"));
System.out.println(match("hello", "h@llo"));
System.out.println(match("hello", "h@@@@"));
System.out.println(match("hello", "h*"));
System.out.println(match("hello", "*l*"));
System.out.println(match("anyString", "*"));
System.out.println(match("help", "h@@@@"));
System.out.println(match("help", "h*"));
System.out.println(match("help", "*l*"));
System.out.println(match("help", "*l*p"));
System.out.println(match("help", "h@llo"));
System.out.println(match("", "*"));
System.out.println(match("", "***"));
System.out.println(match("", "@"));
// I added these test cases on November 25th to
// ensure that everyone has proper code
System.out.println(match("A", "B"));
System.out.println(match("ABCD", "ABDC"));
System.out.println(match("AB", "*C"));
System.out.println(match("ABCDE", "A*F"));
System.out.println(match("ABC", "A@D"));
System.out.println(match("", "*@*"));

Here is the output:


(2) Room Counting

Download the RoomCountingProgram from the website. You must complete two methods. The countRooms() method must recursively determine the number of rooms in the maze. The number of rooms is the number of open areas separated by walls (see table below). The largestRoomSize() method must recursively determine the size of the largest room in the maze (see table below). See image.

Hint: In the countRooms() method, you likely should start off by searching the maze for a blank area (i.e., use double FOR loop) and then once you find a blank area, you should call a function to recursively flood fill the room by marking the 0 locations with a 2 ... returning from the recursive only when the room has been filled. The function should return back to the call from within the double FOR loop of the countRooms() method. You should make a similar recursive method to be called from the largestRoomSize() method.

The testing code (i.e., main method) has 9 mazes.

Your code should return the following results:

Rooms in maze1: 1
Largest room in maze1: 30

Rooms in maze2: 3
Largest room in maze2: 16

Rooms in maze3: 1
Largest room in maze3: 42

Rooms in maze4: 2
Largest room in maze4: 48

Rooms in maze5: 1
Largest room in maze5: 64

Rooms in maze6: 4
Largest room in maze6: 8

Rooms in maze7: 16
Largest room in maze7: 1

Rooms in maze8: 4
Largest room in maze8: 9

Rooms in maze9: 1
Largest room in maze9: 31
Academic Honesty!
It is not our intention to break the school's academic policy. Projects posted are only used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly fill out the form. Please provide a valid email address and we'll get back to you in less than 24 hours. We will be sending an invoice through PayPal upon confirmation. We are a non profit organization however we need an amount to keep this organization running, and to be able to complete our research and development.