You are on page 1of 4

PROBLEM PROMPTS

problem1_nested

Given a string, return true if it is a nesting of one or more pairs of parentheses,


like "(())" or "((()))". If there are any other characters besides parentheses in the
string, return false. Assume the string length will always be > 0.

Examples:
problem1_nested("(())"); // returns true
problem1_nested("((()))"); // returns true
problem1_nested("(((x))"); // returns false
problem1_nested("(((x)))"); // returns false
problem1_nested("()"); // returns true

problem2_countDoubles

We'll say that a "double" in a string is two instances of a char, separated by a


char. So in "AxA", the A's make a double. Doubles can overlap, so "AxAxA"
contains 3 doubles -- 2 for A and 1 for x. Recursively compute the number of
doubles in the given string.

Examples:
problem2_countDoubles("axa"); // returns 1
problem2_parenPart("axax"); // returns 2
problem2_parenPart("axbx"); // returns 1

problem3_countCopies

Given a string and a non-empty substring (sub), compute recursively if at least


n copies of sub appear in the string somewhere, possibly with overlapping. n
will always be non-negative. 

Examples:
problem3_countCopies("catcowcat", "cat", 2); // returns true
problem3_countCopies("catcowcat", "cow", 2); // returns false
problem3_countCopies("catcowcat", "cow", 1); // returns true

Problems 4-5: ToDoList and ToDoItem

For this assignment, you will write a class ToDoItem that implements


the Comparable interface. Compare items first by their priority, then by their
description. Also implement a class ToDoList that maintains a list of to do
items, and provides methods for adding, removing, finding, and getting a

sorted list of items. Use these templates: ToDoItem.java   Download

ToDoItem.java ToDoList.java  Download ToDoList.java


Example:
ToDoList list = new ToDoList();
list.addItem("Walk Robert", 1);
list.addItem("Walk Robert", 1);
list.addItem("Walk Robert", 2);
list.addItem("Walk Robert", 3);
list.addItem("Do 45J Lab", 1);
list.addItem("Grocery shopping", 6);
list.addItem("Take a nap", 4);
list.addItem("Pay bills", 2);
list.addItem("Call Mom", 5);
list.addItem("Do laundry", 1);
list.addItem("Call Dad", 5);

List<ToDoItem> sortedItems = list.getSortedItems();


for (ToDoItem item : sortedItems) {
  System.out.println(item);
}
/* The above prints out:
1 Do 45J Lab
1 Do laundry
1 Walk Robert
1 Walk Robert
2 Pay bills
2 Walk Robert
3 Walk Robert
4 Take a nap
5 Call Dad
5 Call Mom
6 Grocery shopping
*/

System.out.println();
System.out.println(list.findFirstItemWithDescription("Walk Robert")); // prints out "1
Walk Robert"
System.out.println();

list.removeFirstItemWithDescription("Walk Robert"); // returns true


sortedItems = list.getSortedItems();
for (ToDoItem item : sortedItems) {
  System.out.println(item);
}
/* The above prints out:
1 Do 45J Lab
1 Do laundry
1 Walk Robert
2 Pay bills
2 Walk Robert
3 Walk Robert
4 Take a nap
5 Call Dad
5 Call Mom
6 Grocery shopping
*/

System.out.println();
System.out.println(list.findAllItemsWithDescription("Walk Robert"));
// The above prints out: [1 Walk Robert, 2 Walk Robert, 3 Walk Robert]
System.out.println();

list.removeAllItemsWithDescription("Walk Robert"); // returns true


sortedItems = list.getSortedItems();
for (ToDoItem item : sortedItems) {
  System.out.println(item);
}
/* The above prints out:
1 Do 45J Lab
1 Do laundry
2 Pay bills
4 Take a nap
5 Call Dad
5 Call Mom
6 Grocery shopping
*/

System.out.println();
System.out.println(list.findFirstItemWithPriority(1)); // prints out "1 Do 45J Lab"
System.out.println();

list.removeFirstItemWithPriority(1); // returns true


sortedItems = list.getSortedItems();
for (ToDoItem item : sortedItems) {
  System.out.println(item);
}
/* The above prints out:
1 Do laundry
2 Pay bills
4 Take a nap
5 Call Dad
5 Call Mom
6 Grocery shopping
*/

System.out.println();
System.out.println(list.findAllItemsWithPriority(5)); // prints out "[5 Call Dad, 5 Call
Mom]"
System.out.println();

list.removeAllItemsWithPriority(5); // returns true


sortedItems = list.getSortedItems();
for (ToDoItem item : sortedItems) {
  System.out.println(item);
}
/* The above prints out:
1 Do laundry
2 Pay bills
4 Take a nap
6 Grocery shopping
*/

System.out.println();

You might also like