Presentation is loading. Please wait.

Presentation is loading. Please wait.

Copyright by Scott GrissomCh 5 Sophisticated Behavior Slide 1 Java Class Library a very large collection of classes for you to use as needed the challenge.

Similar presentations


Presentation on theme: "Copyright by Scott GrissomCh 5 Sophisticated Behavior Slide 1 Java Class Library a very large collection of classes for you to use as needed the challenge."— Presentation transcript:

1 copyright by Scott GrissomCh 5 Sophisticated Behavior Slide 1 Java Class Library a very large collection of classes for you to use as needed the challenge is to know which ones and when reading and understanding the API is critical available through BlueJ or the web demo for Strings import constructors methods

2 copyright by Scott GrissomCh 5 Sophisticated Behavior Slide 2 Strings methods int length() boolean contains(String) boolean startsWith(String) String [] split(String) String toLowerCase()

3 copyright by Scott GrissomCh 5 Sophisticated Behavior Slide 3 Randomness (5.4) computers generate pseudo-random values that can be repeatable if necessary source code Random myRand = new Random(); val = myRand.nextInt(); val = myRand.nextInt(6); result = myRand.nextBoolean(); Group Activities generate a random response from “yes”, “no”, “it depends” generate a random number between 1 and N generate a random number between min and max

4 copyright by Scott GrissomCh 5 Sophisticated Behavior Slide 4 TechSupport this book project attempts to automate technical phone support by pretending to respond to customer questions the classes inputReader - reads the customer question from the key board Resonder - prints a random response SupportSystem - continues processing requests until ‘bye’ source code refer to book

5 copyright by Scott GrissomCh 5 Sophisticated Behavior Slide 5 HashMap (5.6) A collection of paired data (key, value) the key is used to access the value (instead of an index) keys must be unique examples name and phone number ID and name operations put(key, value) value = get(key) size() isEmpty() clear() Take note duplicate keys replace the previous ones null is returned if no key is found source code HashMap guestList; guestList = new HashMap (); guestList.put(“123”,”Henry”); name = guestList.get(“123”);

6 copyright by Scott GrissomCh 5 Sophisticated Behavior Slide 6 HashSet (5.7) similar to an arraylist only one copy of an item is allowed the order of items is undefined Tech Support System see the code

7 copyright by Scott GrissomCh 5 Sophisticated Behavior Slide 7 Public / private (5.11) Access modifiers define the visibility of methods and fields public items can be seen by any class private items can only be seen from within the class fields should always be private to protect the data information hiding methods are often public but can be private if there is no need for the public to have access

8 copyright by Scott GrissomCh 5 Sophisticated Behavior Slide 8 Constants fields whose values can not be changed compiler will prevent accidental changes private final int MAX = 10; class variables exist at the class level private static int count; these two modifiers are often used together


Download ppt "Copyright by Scott GrissomCh 5 Sophisticated Behavior Slide 1 Java Class Library a very large collection of classes for you to use as needed the challenge."

Similar presentations


Ads by Google