Our variables aren’t just simple numbers anymore. We’ve got complex objects like String and Scanner at our disposal. Today we’ll get more practice at using objects that others have made available.
Reminder: Be sure to get your checkpoints from lab 2 checked off in the first 20 minutes of this lab. They should already be working and ready for approval.
Create a package named lab3 in your cs145 project.
Complete three of the following five tasks. We suggest you create separate classes and main methods for each. You’ll need to browse through the String class documentation to find methods suitable to your needs. To see the documentation, declare a String variable, place your cursor in the type, and hit Shift-F2.
Checkpoint #1. Hit Control-Shift-F in Eclipse to format your code. Show your instructor or TA your three solutions.
The Random class is a source of random numbers. Such numbers have a lot of use, not the least of which is in games. You make a random number generator like you make any object:
Random generator = new Random();
Check out the documentation for Random (Shift-F2 with the cursor inside “Random” or search the Internet for “java 6 random”) and see how it can help you solve this problem:
Checkpoint #2. Hit Control-Shift-F in Eclipse to format your code. Show your TA or instructor your code.