Download presentation
Presentation is loading. Please wait.
Published byLinette Hubbard Modified over 9 years ago
1
CPSC 233 Tutorial Xin Liu Feb 14, 2011
2
Tips on keyboard input How to detect that the user just hit enter when prompted for a string import java.util.Scanner; class StringShort { public static void main (String [] args) { Scanner in = new Scanner(System.in); String st = in.nextLine (); if (st.length() == 0) System.out.println("Blank"); else System.out.println("Not blank"); }
3
String Comparison aString.compareTo (String anotherString)aString.compareToIgnoreCase (String anotherString) returns negative integer if aString < anotherString positive integer if aString > anotherString 0 if aString == anotherString
4
String Comparison – an example public class StringCompare { public static void main (String [] args) { String s1; String s2; int comparison; // Case 1: s1 before s2 s1 = "aaa"; s2 = "aab"; comparison = s1.compareToIgnoreCase(s2); System.out.println(s1 + " " + s2 + " " + comparison); // Case 2: s2 before s1 s1 = "aaa"; s2 = "a"; comparison = s1.compareToIgnoreCase(s2); System.out.println(s1 + " " + s2 + " " + comparison); // Case 1: s1, s2 identical s1 = "wei!"; s2 = "wei!"; comparison = s1.compareToIgnoreCase(s2); System.out.println(s1 + " " + s2 + " " + comparison); } The output: aaa aab -1 aaa a 2 wei! wei! 0
5
Debug Mode What is “Debug Mode”? A mode in which some detailed info is printed to help find errors How to implement? 1. Make a boolean-type “global variable” (using a static attribute) 2. Print out some info when the boolean variable is true
6
Debug mode – an example public class DriverDebug { public static void main (String [] args) { if (Mode.debug == true) { // First debug message: never appears because by default mode is off System.out.println(">>Debug message: "); } // Second debug message: appears because it's now turned on. Mode.debug = true; if (Mode.debug == true) { System.out.println(">>Debug message: "); } public class Mode { public static boolean debug = false; }
7
Draw UML with MS Word Classes Insert a “text box” Insert a 2-row table in the text box write class name in the first row write attributes and methods in the second row use a “-” for private use a “+” for public Relationships Draw lines with/without arrow heads Multiplicities Insert a “text box” write a number in the text box
8
Linked list -- continued Add “debug mode” Add new methods insertInOrder () insert new nodes to positions so that the list is in an ascending order removeWithName () remove a node with given book name
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.