In Lab 6
October 9, 2007
Purpose:
The purpose of this lab is to re-inforce your object oriented programming skills, start using control structures, as well as get you used to using the Java API.
What to do:
You will need a Driver class that holds your main method. In the main method you will instantiate the second class you will need, the StringParser class. The StringParser constructor will initialize 4 Strings that you get from user input. You can use the Scanner class or JOptionPane to accept user input. After you initialize the Strings you will automatically return back to the Driver class. The driver class will call a method in the StringParser class to start the program.
The method to start the program will go into a loop and print the menu below.
The menu will consists of five choices:
- Press 1 to find the largest String.
- Press 2 to search for a a particular String.
- Press 3 to search for a particular substring anywhere in the string.
- Press 4 to exit.
You should use a iteration statement, print the menus and use a if/else statement to call the appropriate methods in the StringParser class to complete the tasks chosen in the menu.
- For choice 1 you will call your method to handle the choice. In your method you will call the Java API. The String class has a method that you can use to find out the length, you need to get used to using the Java API.
- For choice 2 in your method that will handle the choice take user input to take another string and search through your first four strings to see if the new String is in there. Don't use ==, String has a method in the API to check for equality.
- For choice 3 call your method and then use another String Java API method call to handle choice 3.
- For choice 4 print goodbye and exit.
- Any other choices selected prompt that the choice is incorrect and loop back around to print the menu again.
Hint
Compile often. First get the two classes up and running with the proper code in the constructor of the StringParser class. Then get the static menu method working, then the switch statement calling the correct methods, enclose that in the loop so it will work until 5 is input. Then start writing each method, method by method. Use the String methods in the Java API to solve the problems stated in the menu.
Turn in
Get as much as you can done before you leave the lab. Make sure your TA or
Consultant checks off what you have completed before you leave the lab. If
you don't finish before the end of the lab, make sure you have it turned
in by Thursday evening. Debzani will be going over this in lecture on
Friday and your lab must be turned in before she goes over it.