{\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\fnil Courier New;}} {\colortbl ;\red0\green0\blue0;\red63\green127\blue95;\red127\green0\blue85;\red0\green0\blue192;} {\*\generator Msftedit 5.41.21.2508;}\viewkind4\uc1\pard\cf1\lang1033\f0\fs24 \cf2 /* PRE: X is an array of integer values, key is an integer to search for\cf0\par \cf2 * POST: If found, returns the position of 'key' in the array X. If not\cf0\par \cf2 * found, returns -1.\cf0\par \cf2 */\cf0\par \cf1 \cf3\b public\cf1\b0 \cf3\b static\cf1\b0 \cf3\b int\cf1\b0 search(\cf3\b int\cf1\b0 X[], \cf3\b int\cf1\b0 key)\cf0\par \cf1 \{\cf0\par \cf1 \cf3\b for\cf1\b0 (\cf3\b int\cf1\b0 i = 0; i < X.\cf4 length\cf1 ; i++)\cf0\par \cf1 \{\cf0\par \cf1 \cf3\b if\cf1\b0 (X[i] == key)\cf0\par \cf1 \cf3\b return\cf1\b0 i;\cf0\par \cf1 \}\cf0\par \cf1 \cf3\b return\cf1\b0 -1;\cf0\par \cf1 \}\cf0\par } 170926376{\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\fnil Courier New;}} {\colortbl ;\red0\green0\blue0;\red63\green127\blue95;\red127\green0\blue85;\red0\green0\blue192;} {\*\generator Msftedit 5.41.21.2508;}\viewkind4\uc1\pard\cf1\lang1033\b\f0\fs28 \cf2 /* PRE: X is an array of integer values, key is an integer to search for\cf0\par \cf2 * POST: If found, returns the position of 'key' in the array X. If not\cf0\par \cf2 * found, returns -1.\cf0\par \cf2 */\cf0\par \cf1 \cf3 public\cf1 \cf3 static\cf1 \cf3 int\cf1 search(\cf3 int\cf1 X[], \cf3 int\cf1 key)\cf0\par \cf1 \{\cf0\par \cf1 \cf3 for\cf1 (\cf3 int\cf1 i = 0; i < X.\cf4 length\cf1 ; i++)\cf0\par \cf1 \{\cf0\par \cf1 \cf3 if\cf1 (X[i] == key)\cf0\par \cf1 \cf3 return\cf1 i;\cf0\par \cf1 \}\cf0\par \cf1 \cf3 return\cf1 -1;\cf0\par \cf1 \}\cf0\par } 200296403{\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\fnil Courier New;}} {\colortbl ;\red127\green0\blue85;\red0\green0\blue0;\red0\green0\blue192;} {\*\generator Msftedit 5.41.21.2508;}\viewkind4\uc1\pard\cf1\lang1033\b\f0\fs32 package\cf2\b0 arrays;\cf0\par \par \cf1\b public\cf2\b0 \cf1\b class\cf2\b0 PhoneEntry\cf0\par \cf2\{\cf0\par \cf2 \cf1\b private\cf2\b0 String \cf3 first\cf2 ;\cf0\par \cf2 \cf1\b private\cf2\b0 String \cf3 last\cf2 ;\cf0\par \cf2 \cf1\b private\cf2\b0 String \cf3 phone\cf2 ;\cf0\par \cf2 \cf1\b private\cf2\b0 String \cf3 email\cf2 ;\cf0\par \cf2 \cf0\par \cf2 \cf1\b public\cf2\b0 PhoneEntry(String first, String last, String phone, String email)\cf0\par \cf2 \cf1\b public\cf2\b0 \cf1\b int\cf2\b0 compareToIgnoreCase(PhoneEntry e)\cf0\par \cf2 \cf1\b public\cf2\b0 String getFirst()\cf0\par \cf2 \cf1\b public\cf2\b0 String getLast()\cf0\par \cf2 \cf1\b public\cf2\b0 String getPhone()\cf0\par \cf2 \cf1\b public\cf2\b0 String getEmail()\cf0\par \cf2 \cf1\b public\cf2\b0 String toString()\cf0\par \cf2\}\cf0\par } 1992310716{\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\fnil Courier New;}} {\colortbl ;\red0\green0\blue0;\red63\green127\blue95;\red127\green0\blue85;\red0\green0\blue192;} {\*\generator Msftedit 5.41.21.2508;}\viewkind4\uc1\pard\cf1\lang1033\b\f0\fs28 \cf2 /* PRE: X is an array of integer values, key is an integer to search for\cf0\par \cf2 * POST: If found, returns the position of 'key' in the array X. If not\cf0\par \cf2 * found, returns -1.\cf0\par \cf2 */\cf0\par \cf1 \cf3 public\cf1 \cf3 static\cf1 \cf3 int\cf1 search(\cf3 int\cf1 X[], \cf3 int\cf1 key)\cf0\par \cf1 \{\cf0\par \cf1 \cf3 for\cf1 (\cf3 int\cf1 i = 0; i < X.\cf4 length\cf1 ; i++)\cf0\par \cf1 \{\cf0\par \cf1 \cf3 if\cf1 (X[i] == key)\cf0\par \cf1 \cf3 return\cf1 i;\cf0\par \cf1 \}\cf0\par \cf1 \cf3 return\cf1 -1;\cf0\par \cf1 \}\cf0\par } 200296403{\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\fnil Courier New;}{\f1\fnil\fcharset0 Courier New;}} {\colortbl ;\red127\green0\blue85;\red0\green0\blue0;\red0\green0\blue192;} {\*\generator Msftedit 5.41.21.2508;}\viewkind4\uc1\pard\cf1\lang1033\b\f0\fs24 public\cf2\b0 \cf1\b class\cf2\b0 PhoneBook \cf1\b extends\cf2\b0 JFrame\cf0\par \cf2\{\cf0\par \cf2\f1 // other fields\cf0\f0\par \cf2 \cf0\par \cf2 DefaultListModel \cf3 listData\cf2 = \cf1\b new\cf2\b0 DefaultListModel();\cf0\par \cf2 JList \cf3 list\cf2 = \cf1\b new\cf2\b0 JList(\cf3 listData\cf2 );\par \par \f1 \cf0\f0\par } 185478811{\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\fnil Courier New;}{\f1\fnil\fcharset0 Courier New;}} {\colortbl ;\red127\green0\blue85;\red0\green0\blue0;\red0\green0\blue192;} {\*\generator Msftedit 5.41.21.2508;}\viewkind4\uc1\pard\cf1\lang1033\b\f0\fs28 public\cf2 \cf1 static\cf2 \cf1 int\cf2 search(\cf1\f1 String\cf2\f0 X[], \f1 String\f0 key)\cf0\par \cf2 \{\cf0\par \cf2 \cf1 for\cf2 (\cf1 int\cf2 i = 0; i < X.\cf3 length\cf2 ; i++)\cf0\par \cf2 \{\cf0\par \cf2 \cf1 if\cf2 (X[i\f1 ].equals(\f0 key\f1 )\f0 )\cf0\par \cf2 \cf1 return\cf2 i;\cf0\par \cf2 \}\cf0\par \cf2 \cf1 return\cf2 -1;\cf0\par \cf2 \}\cf0\par } 51593096