Oop 12
Oop 12
Lecture-12
1
Lecture Outline
2
The Java class library
Thousands of classes
Tens of thousands of methods
Many useful classes that make life much Easier
A competent Java programmer must be able to work
with the libraries
3
The Java class library
You should:
• know some important classes by name
• know how to find out about other classes
Remember:
• We only need to know the interface, not the implementation
The interface of a class describes what a class does and how it
can be used without showing the implementation.
The complete source code that defines a class is called the
implementation of that class.
4
A Technical Support System
TechSupport is a program intended to provide technical support
for customers.
DodgySoft software company., had a technical support
department with people sitting at telephones.
Customers could call to get advice and help with their
technical problems with the DodgySoft software products.
Recently, business has not been going so well, and dodgySoft
decided to get rid of the technical support department to save
money.
5
A Technical Support System
6
A Technical Support System
7
A Technical Support System
unchanged.
9
Checking string equality
if(input == "bye")
{ // does not always work!
...
}
11
Checking string equality
12
Checking string equality
13
Checking string equality
14
Checking string equality
15
Adding Random Behavior
17
The Random class
The following illustrates the code needed to generate and
print a random integer number:
Random randomGenerator;
randomGenerator = new Random();
int index = randomGenerator.nextInt();
System.out.println(index);
18
The Random class
The Random class also offers a method to support this.
It is again called nextInt, but it has a parameter to specify
the range of numbers that we would like to use.
Find the nextInt method in class Random that allows
the target range of random numbers to be specified. What
are the possible random numbers that are generated
when you call this method with 100 as its parameter?
Write a method in your RandomTester class called
throwDice that returns a random number between 1 and 6
(inclusive).
19
The Random class
20
Generating random responses
21
Maps
22
Maps
23
Maps
24
Maps
25
Maps
26
Maps
27
Maps
28
Maps
29
Maps
30