SlideServe
Menu
Préférences
© SlideServe · v2026

CPSC 233 Tutorial

gavril avatar
8 diapositives · 252 Views · Jul 25, 2014

CPSC 233 Tutorial. Xin Liu Feb 14, 2011. 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 );

CPSC 233 Tutorial - slide 1
01 / 8CPSC 233 Tutorial
1 / 17

Télécharger la présentation

CPSC 233 Tutorial
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  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: aaaaab -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? • Make a boolean-type “global variable” (using a static attribute) • Print out some info when the boolean variable is true

  6. Debug mode – an example public class Mode { public static boolean debug = false; } 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: <Insert debugging message here>"); } // Second debug message: appears because it's now turned on. Mode.debug = true; if (Mode.debug == true) { System.out.println(">>Debug message: <Insert debugging message here>"); } } }

  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