

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
In this lecture, students are introduced to the java random class for generating random numbers and learn how to use it to simulate rolling dice. The lecture also covers string manipulation, specifically focusing on the startswith and endswith methods, and demonstrates how to modify the tech-support application to generate random responses. Students are asked to modify the responder class to use a random object and an arraylist of possible responses, and to email the updated file to the instructor.
Typology: Study notes
1 / 3
This page cannot be seen from the preview
Don't miss anything!


Announcements: Read section 5.5, 5.6, 5.8, and 5.9 (last time: 5.1 to 5.4) Last Time: Random Numbers Java includes a class for generating random numbers. What is it called? What package is it contained in? (That is, where do you need to tell Java to look for the Random class in an import statement?) How do you create an instance of a Random? How do you generate a random number?
Discuss ways that students used random numbers to select DNA characters. The class Random has an overloaded constructor: public Random() public Random( long seed ) Both create a random number generator. The second version takes a seed value as a parameter. This "primes" the generator. Two random number generators created using the same seed value will generate the same sequence of 'random' numbers. The nextInt method returns a random number. This method is also overloaded: public int nextInt() โ return a random int in the range -2,147,484,648 to 2,147,484,647. public int nextInt( int max ) โ return a random int in the range 0 to max-1. So, how would we use a Random number generator to simulate rolling a single die? How about two dice?
Tech-Support Let's look at an application that does some String manipulation. Open the tech-support application (in chapter 5 folder) Go ahead and create a SupportSystem object. Tell it about your computing problems. It's not a very good system, is it? There are 3 classes: SupportSystem, InputReader, and Responder. The InputReader class gets user input. The Responder class generates a response. Let's look at the Responder class. Not much here yet, is there? Let's examine the code of class SupportSystem: