Due 11/5 (Sunday) by noon
You can see a video version of this lesson here: https://www.youtube.com/watch?v=RrNIEECb9F0 and https://www.youtube.com/watch?v=dbf3Qwbd5-U
This lab contains three new .java files – StringList, ExamDates and ExamDatesDriver. Please submit StringList.java, ExamDates.java and ExamDatesDriver.java to your google drive folder - you will also need to submit a copy of Date.java - please make sure there is exactly ONE copy of Date.java in your folder, otherwise my program will get very confused if it sees two Date.java files. (I have attached a copy that you can use) As always, take care to make sure all your file names and method names match the exact names that I have.
0. Please remove all of your old labs from your turn-in folder! They have all been graded.
1. You will write a program called StringList, which is a collection of methods dealing with ArrayLists of Strings. To test your methods (highly recommended), write a main method, create ArrayLists in main, and test them in there. All of your methods here should be static, as this class is not creating an object. The point of this lab is for you to get comfortable using the functions of ArrayList. Write the following methods (I have given the method header for the first one, you will have to figure out the rest beyond the name):
public static void main() - you don't have to put anything specific in here when you turn this project in, but you should use this method to create ArrayLists of Strings and call your other methods.
public static int length(ArrayList<String> words) – this method should return the size of the ArrayList words that is passed to this function. This is a very short method.
totalLength – this method should input an ArrayList of Strings and return the total length of all of the Strings in the list combined (an int). For example, if you send it ["happy","boo boo", "john"] the total length of all the words combined is 16.
add(ArrayList<String> words, String newWord) – this method should input an ArrayList of Strings and a String (in that order), then add newWord to the end of the ArrayList of words and return the updated ArrayList of Strings. So if words is ["kate","susan","alan"] and newWord is "johnny" the method should return the list ["kate","susan","alan","johnny"].
indexOf – this method should input an ArrayList of Strings, and a String (in that order), and return the int location of the first occurrence of the second String. If the String is not found in the ArrayList it should return -1, just like the indexOf for String. So if you sent it ["banana", "happy", "banana" and "bob"] and the String "banana" it will return 0 because it first appears in slot 0. If you sent it "bob" it should return 3, if you send it "win" it should return -1 because "win" is not in the list. [NOTE: there is a built-in indexOf already for arraylists, but it works poorly. Do not use it, write your own with a for loop.]
count – this method should input an ArrayList of Strings, and a String (in that order), and return how many times the String is found in the ArrayList (an int). So if you sent it ["banana", "happy", "banana" and "bob"] and the String "banana" it will return 2 because it appears twice.
addOrder(ArrayList<String> words, String newWord) – this method should input an ArrayList of Strings (which you can assume is already in alphabetical order) and a String (in that order), then add newWord in the proper alphabetical order (remember that a.compareTo(b) tells you about the alphabetical order, if a.compareTo(b) is < 0, a comes before b) to words. addOrder should then return this updated ArrayList of Strings.
For example, if words = ["billy", "jimmy", "kelly"], and newWord = "joann", this method should return: ["billy", "jimmy", "joann", "kelly"]
For example, if words = ["billy", "jimmy", "kelly"], and newWord = "xena", this method should return: ["billy", "jimmy", "kelly", "xena"]
For example, if words = ["billy", "jimmy", "kelly"], and newWord = "alexa", this method should return: ["alexa", "billy", "jimmy", "kelly"]
NOTE: I will NOT test this method by sending it an unordered ArrayList, so don't worry about that. Assume that the ArrayList input named words is already in alphabetical order.
HINT: loop through to find the correct spot, checking to see if your new element comes before each element in the list. If this never happens, add it at the end! Make sure that you only add it once (return right away once you add it), and make sure it will always get added somewhere! Test this thoroughly.
2. You will write a program called ExamDates.java. This class will represent an object storing the dates of all of your tests for a certain subject in school.
You should have two pieces of instance data – an ArrayList of Date objects (preferably using my attached version of Date, download from this folder: https://drive.google.com/drive/folders/1VuTI2RXdQ3o-Ri8YX4W04Q0ciuo4GIXo?usp=sharing) named "calendar" and a String called "subject". Write the following methods:
(a constructor) – your constructor should have one input: a String for the subject. It should set your subject variable to be the input of the constructor, and it should set the calendar instance variable to be an empty ArrayList of Dates (like this: calendar = new ArrayList< ...).
numberTests() – this method should take no inputs and return an int, which should be the size of the calendar ArrayList
getCalendar() - this is an accessor method that returns the ArrayList and take no inputs.
addTest – this void method should input a Date object, and put that inputted Date at the end of the calendar ArrayList
addTestFirst – this void method should input a Date object, and put that inputted Date in slot 0 (the front) of the calendar ArrayList, pushing everything else down the line.
containsDate – this method should input a Date object and return a boolean (NOT a Boolean, which is actually the wrapper class for boolean) that tells whether or not the inputted date is in the calendar ArrayList (essentially, whether there is a test on that day). You will need to compare the month, day and year of the input and make sure they are all the same.
printDates - this void method should take no inputs and print out the calendar instance variable.
You may use your version of Date or the version I have uploaded below.
3. Now, let's test this ExamDates out! To do this, make a ExamDriver class, and in main, create an ExamDates object. Inside this class, you should just provide method calls to set up an ExamDates object and test each of the methods inside a main.
Here is an example of what that might look like:
ExamDates p = new ExamDates("math");
//now you are ready to call methods on your object!
Date halloween = new Date(10,31,2005);
Date xmas = new Date(12,25,2005);
p.addTest(halloween);
p.addTest(xmas);
System.out.println( p.numberTests() ); //hopefully this is 2
p.printDates(); //this should show the array
...
//etc.
When you are done, make sure to submit StringList.java, ExamDates.java, ExamDriver.java and Date.java (you need to submit Date so your ExamDates will work properly)
(You can use my version of Date in this folder: https://drive.google.com/drive/folders/1VuTI2RXdQ3o-Ri8YX4W04Q0ciuo4GIXo?usp=sharing)